As the question pretty much sums up, I’m doing a presentation on some of the more “hidden” aspects of jQuery, including the data() function.
I’m quite comfortable with how the function works, but am struggling to come up with enough actual usage examples outside of basic setting / getting and identifying the events bound to an element.
What else have you used $('#myElement').data() for?
When creating jQuery plugins, I usually use the .data() functions to hold state of an element. For example, say you’re creating a plugin that shows a watermark text when no text has been entered in a text box, you can use .data() to store the state of the text box: