danielstocks / jQuery-Collapse

A lightweight (~1kb) jQuery plugin that enables expanding and collapsing content
http://webcloud.se/jQuery-Collapse/
MIT License
679 stars 153 forks source link

Element ID no longer required? #75

Closed PayBas closed 8 years ago

PayBas commented 9 years ago

As in the example above, the target element (#demo) will require an ID in order for the persistence to work.

It seems to be working fine without an ID nowadays. Did something change? If so, nice work ;). Or is this the difference between HTML5 storage and cookie storage?

But if it's no longer required, perhaps the documentation should probably be updated.

danielstocks commented 9 years ago

Thanks for pointing that out. This is what's happening:

If the ID of an element is not set it will return an empty string, so as a kind of side effect this will actually work as long as you have only one collapsible component on the entire site. If you instantiate the plugin on several sections, there will be a naming collision and they will overwrite each others state.

So to avoid confusing bugs I'm probably going to throw a warning if someone is trying to use persistent option without specifying id.