Reputation: 2173
I have a question regarding jQuery. I have a li
that slides out, now I want to remember if it has slided out so I want to set a boolean variable slidedOut
.
Is it possible to simply add it to the element? Or should I add a hidden div
or something to to element?
Upvotes: 13
Views: 15206
Reputation: 138017
Another option is to use CSS classes. This is particularity useful if you don't really save data (just a flag), or want to change the design for these <li>
s or their children.
.addClass('visited')
- Add the class when needed..hasClass('visited')
- Checks if the element has this class.removeClass('visited')
Upvotes: 1
Reputation: 81660
Using jquery data is considered the standard way to do it - although there are tons of other ways to do it.
An alternative is simply:
$("#myli")[0].slidedOut = true;
alert($("#myli")[0].slidedOut);
Upvotes: 1