File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes jQuery -- add remove list item Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jQuery -- add remove list item" Watch "jQuery -- add remove list item" New topic
Author

jQuery -- add remove list item

William Rouse
Ranch Hand

Joined: Apr 12, 2006
Posts: 73
I was looking at the JQuery for absolute beginner instructional video where I was shown how to add and remove an item for an ordered list. The demo assumed that you had one unordered list on a page. I tried to create a demo where there are two unordered list on a page, but I only want to manipulate one with an ID of loc. I was unsuccessful. Please point me in the correct direction. My code follows…
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
JQuery Selectors page needs to be your friend: http://docs.jquery.com/Selectors

You want to use the id selector with the element

$("#id element")

Eric



William Rouse
Ranch Hand

Joined: Apr 12, 2006
Posts: 73
Thanks Eric I think I have it working.
In the change code line 13 was:

and is now

line 18 was


and is now


This seems to work but I have a related questions doing with the counter and a page refresh. If I execute the HTML and then stop and refresh the page the counter does not go back to the number of list item that is present on the page, but holds the value of the page before it was refreshed. Is there a way to reinitialize the counter?
I tried this for lines at the beginning of the function, but it was of no value.

Thanks!
WBR
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Um, I think that counter issue is sort of impossible....

$("li").size would still be counting the elements from both lists.

Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jQuery -- add remove list item
 
Similar Threads
List item disappears in Firefox
Question on how to implement multi level menu (navigation bar) in html/css
jquery accordion is causing jquery treeview picker to breakup
Problem with struts-menu for second level submenu
jquery accordion and tabs on the same page