I often read it's bad practice, because it's hard to maintain, but doing:
document.getElementsByTagName("h1")[0].foo = {"key":"value"};
compared to using the recommended jQuery alterantive:
$.data($(document.getElementsByTagName("h1")[0]), "foo", {"key":"value"});
is just so much faster: jsperf
Both data
and my hack are not visible in a debugger like Firebug, so from a "visibility" point of view there is no difference in using either one.
Question:
Why is bad practice to store information directly on the element?