Thursday, 22 August 2013

Wrap nested elements with jQuery

Wrap nested elements with jQuery

I am using jQuery to wrap a li tag around all p elements, like so:
$('p').wrapAll('<li class="text_box" />');
However, this is not quite right for what I need. Eventually, I need to
produce :
<li>
<div class="text_box">
<p> content </p>
</div>
</li>
I need jQuery to have the p tag wrapped in the div, which is then wrapped
in a li element.
Does anyone know how this is done?

No comments:

Post a Comment