Attributes for passing data in HTML

I use jQuery and for performing dynamic calculations I need to save some information along the anchor tag, for example:

<a href="blah.html" username="some value" age="12" address="blah">click</a>

Of course, this code will not pass the test, and since I need, for example, some data to be stored using the attribute rel, it will not be enough. I know that HTML5 solves this problem, but meanwhile (until HTMl5 is fully adopted), what other options do I have?

Thank,

Joel

+3
source share
1 answer

You can attribute your address attribute "data-" and access it using $.data, for example:

<a href="blah.html" username="some value" age="12" data-address="blah">click</a>


alert($("a").data("address"));

Try it here.

+6
source

Source: https://habr.com/ru/post/1786397/


All Articles