• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jQuery -- add remove list item

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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…
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, I think that counter issue is sort of impossible....

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

Eric
 
knowledge is the difference between drudgery and strategic action -- tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic