Possible Duplicate:
Using .after() to add html closing and open tags
I am in need of adding some HTML before a <li>
and after the same <li>
.
The selector works, but when it adds the HTML it also closes the <div>
s with adding </div>
. I need it to be open.
my code:
$('#ja-megamenu .level1').before('<div class="childcontent cols1 ">');
NOTE:
I need it to add ONLY <div class="childcontent cols1 ">
before the li
(with class="level1")
then later I'll use:
$('#ja-megamenu .level1').after('</div>');
to add the closing </div>
This code doesn't work. How can I get this to work?
Have been reading documentation all day long, but haven't found the answer yet...
Thank you :-)
You can not do that, if you want to add a div around an element, use jQuery's wrap().
$('#ja-megamenu .level1').wrap('<div class="childcontent cols1 "></div>');
BUT the problem you have is a div can not wrap an li! You need to do something else.
Though this HTML is not valid (<li>
's parent could not be <div>
), you may use wrap()
:
$("#ja-megamenu .level1").wrap("<div class='childcontent cols1' />");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With