Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Add a growing number class to list items and divs

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #30616
    noahgelman
    Participant

    I have a ul or list items and I wan to add classes to them dynamically like so.



  • ...


    How would I do this?
    (also, the class names are generic examples, the important part is the number)

#77621
ImpInaBox
Member

If you write your page in PHP (or ASP I guess) you can dynamically generate the classes or targets based on a loop counter – for ($i=1; $i++; $

#77631
noahgelman
Participant

No, php wont work, the lists and divs aren’t being generated dynamically. I have some jquery to make some list-items and some divs interact with each other and I need them to have a relatable class. I could hard code it, but if I have a lot it becomes a lot of work and the jquery wouldn’t be very dynamic.

#77635
jheinrichs79
Member

You might want to look at an article I wrote on my blog:
http://jaredheinrichs.com/how-to-create-and-remove-html-elements-using-jquery.html

#77640
noahgelman
Participant

Thanks guys, I’ll try your solutions on Monday

#77564
noahgelman
Participant

@TT_Mark, thanks, it worked perfectly.

@jheinrichs79
, thank you too

#77419
noahgelman
Participant

:)

#63346
soap
Participant

Hey this helped me too! r00lz.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.