Monday, August 27, 2012

Expandos

How to work with custom HTML attributes, to be compatible with all modern browsers?
If you are using jQuery, it can be just done via a .attr() call, but
more correct way is name your custom attributes with prefix "data-" as the HTML5 standard suggest, like
<div data-attrib_name="attrib value">
Address it from the script as
$(elem).data("attrib_name")
and to put a new value:
$(elem).data("attrib_name","new value")

No comments:

Post a Comment