HTML data attributes with jquery
I’ve been much happier coding client-side (remember, I am not Client Side Guy) since I’ve discovered the data attribute specifications in HTML5. With these new data attributes you can add custom attributes and values to html tags and still have them be valid!
<div id="myDiv" data-foo="bar" >
var getVar = $("#myDiv").data("foo"); alert(getVar);
The above piece of code finds the data-foo attribute very easily and our alert would respond with the attached value: “bar”.
This has really changed my client side coding and helps make more sense to those that aren’t as comfortable in code to understand. No more dummy elements to pass around values for me!