469,927 Members | 1,357 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

How to insert new item in middle of unordered list

Good Morning,
I have an unordered list similar to:

<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>

I want to be able to insert a new list item anywhere in the list, for
example, between Item 1 and Item2.

How can this be done with Javascript and DOM?
Cheers!
Jan 5 '06 #1
1 8874
michael escreveu:
Good Morning,
Good night :D
I have an unordered list similar to:
<ul>
<li>Item 1</li>
:
</ul>

I want to be able to insert a new list item anywhere in the list, for
example, between Item 1 and Item2.


ULElement.inserBefore(newLI, referenceLI);

ex:
var ul = document.getElementById("myList"), li =
document.createElement("li");
ul.insertBefore(li, ul.getElementsByTagName("li")[1]);
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Jan 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Geoffrey KRETZ | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.