开发者

Attributes for passing data in HTML

开发者 https://www.devze.com 2023-02-05 17:58 出处:网络
I am using jQuery and in order to perform dynamic computations I need to store some information along an anchor tag, such as:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消