By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

How to insert new item in middle of unordered list

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.