vendredi 8 mai 2015

How do you .unwrap() an element specified number of levels

Is there a way to use Jquery's .unwrap() multiple times without copying and pasting? It'd be nice if it could accept an argument or something like: .unwrap(4) but it doesn't. Is there a more clever solution to achieving the following:?

$(".foo a").unwrap().unwrap().unwrap().unwrap();
<li class="foo">
    <div>
        <ul>
            <li>
                <div>
                    <a href="#">Link</a>
                </div>
            </li>
        </ul>
    </div>
</li>

Aucun commentaire:

Enregistrer un commentaire