I have a List
<ul>
<li id="lst1"> list item One</li>
<li id="lst2"> list item two</li>
<li id="lst3"> list item three</li>
<li id="lst4"> list item four</li>
<li id="lst5"> list item five</li>
</ul>
and i want to append an item between (not inside) "lst2" and "lst3" i don't know how using jquery. Thanks.
First, select the ul element by its id ( menu ) using the getElementById() method. Second, create a new list item using the createElement() method. Third, use the insertAfter () method to insert a list item element after the last list item element.
Use List<E>#add(int, E) to specify the position at which an element will be added to a list. Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
$('#lst3').before('<li id="lst21"> list item three</li>');
You may try this.
You can use after
doc or insertAfter
doc:
$('#lst2').after('a');
$('a').insertAfter('#lst2');
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