Do HTML5 custom data attributes “work” in IE 6?

You can retrieve values of custom (or your own) attributes using getAttribute. Following your example with <div id=”geoff” data-geoff=”geoff de geoff”> I can get the value of data-geoff using var geoff = document.getElementById(“geoff”); alert(geoff.getAttribute(“data-geoff”)); See MSDN. And although it is mentioned there that you need IE7 to get this to work, I tested this a … Read more

Selecting element by data attribute with jQuery

$(‘*[data-customerID=”22″]’); You should be able to omit the *, but if I recall correctly, depending on which jQuery version you’re using, this might give faulty results. Note that for compatibility with the Selectors API (document.querySelector{,all}), the quotes around the attribute value (22) may not be omitted in this case. Also, if you work with data … Read more

jQuery Data vs Attr?

If you are passing data to a DOM element from the server, you should set the data on the element: <a id=”foo” data-foo=”bar” href=”#”>foo!</a> The data can then be accessed using .data() in jQuery: console.log( $(‘#foo’).data(‘foo’) ); //outputs “bar” However when you store data on a DOM node in jQuery using data, the variables are … Read more