Attributes for passing data in HTML
I am using jQuery and in order to perform dynamic computations I need to store some information along an anchor tag, such as:
<a href="blah.html" username="some value" age="12" address="blah">click</a>
开发者_运维技巧Of course this code will not pass validation, and since I need more than one data to store using rel
attribute, for example, wouldn't be enough. I know HTML5 addresses this issue ,but int the meantime (until HTMl5 is fully accepted) what other options do I have?
Thanks,
Joel
You can prefix your address attribute with 'data-' and access it using $.data
like so:
<a href="blah.html" username="some value" age="12" data-address="blah">click</a>
alert($("a").data("address"));
Try it here.
精彩评论