Hello
I have this:
<ul id="pickme">
<li>1</li>
<li>2</li>
<li>3
<ul>
<li>3-1</li>
</ul>
</li>
</ul>
But want this:
<ul id="pickme">
<li>1</li>
<li>2</li>
<li>3</li>
<li class="new_ul">
<ul>
<li>3-1</li>
</ul>
</li>
</ul>
With other words I need to insert
</li><li class="new_ul">
after the 3 in the list. I have played with .append and .prepend but witout beeing able to insert at the right place.
Any help would be appreciated
Br. Anders
There is a correct answer below. If you use that then it will run through only one level. But same example is is capable of running through multible levels. Just change ('>li>ul') to ('ul') and all nested ul's will be found and handled. Perfect!
(will run through endless levels of nested ul's)
$('#pickme').find('ul').each(function() {
$(this).wrap('<li class="new_ul"></li>').parent().insertAfter($(this).parent().parent());
});
In this case this:
<ul id="pickme">
<li>1</li>
<li>2</li>
<li>3
<ul>
<li>3-1
<ul>
<li>3-1-1</li>
</ul>
</li>
</ul>
</li>
</ul>
Will be:
<ul id="pickme">
<li>1</li>
<li>2</li>
<li>3</li>
<li class="new_ul"> <<new li
<ul>
<li>3-1</li>
<li class="new_ul"> <<new li
<ul>
<li>3-1-1</li>
</ul>
</li>
</ul>
</li>
</li>
</ul>