简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM