Search code examples
javascriptcollapsable

How do I create separately collapsible divs for dynamic content?


I want to create a list that is actually a list of collapsible divs on my site. So when you click on an item on the list, more information will become visible.

I'm using animatedcollapse from http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm

The problem is that since I'm looping over divs, they all have the same id, and thus 'opening' any of the divs will open all of the divs.

Should I make unique id's for every div? How is it done?

Thanks a lot for your help. I'm using Django.


Solution

  • id's in an html page should always be unique. When you're looping, you can append the loop index to your id, to make it unique.