Is there a way to replace, with Jquery, this:
<ul class="sub-menu">
<li><a href="#">Link</a></li>
</ul>
to this:
<div class="under">
<p><a href="#">Link</a></p>
</ul>
Parent element is: <ul id="menu">
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could unwrap the
aelement and then wrap it in the new elements:The two calls to
unwrapremove theliand then theul, and the two calls towrapadd thedivand thep. Note that we have to wrap thedivfirst, then thep.Here’s a working example (inspect the DOM in the results window to see what you end up with).
Note that I’m assuming the closing
ulwas meant to be a closingdivtag in your second example!Edit
You could also combine the two calls to
wrap, which should be faster:Another edit
Using
unwraptwice seemed a little messy to me. Now that I’ve had a little spare time I’ve thrown together a simple plugin that allows you to unwrap multiple ancestor elements from a target element. I’ve called itunwrapUntil, and you can find it on GitHub. It will work for any number of unwraps, and using it in this specific case would probably be a bit extreme, but it would allow us to do the following: