I've recently refactored out a couple of uses of jQuery's data method, and I'd like to explain why.
In case you've not seen it before, data gives you access to a key/value store attached a single element. You use it with the same kind of get/set syntax found in other jQuery methods:...
There are a few problems with this method, and I'd advise against using it.
Unlike most other jQuery methods, if you call data on a list of elements, it affects only the first one. This makes reasoning about code that uses data hard: you must ask, "might this be a list? Which element is this affecting?"
Your new post is loading...