I have a few links:
<a href="div1">link1</a>
<a href="div2">link2</a>
<a href="div3">link3</a>
And containers:
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
When a user clicks o开发者_开发问答n a link the script gets container's Id from href attribute and shows correct div. But i don't want to use href attribute for that purpose. Is there any standard attribute for storing additional info?
Data Attributes. They're non-standard for HTML revisions less than 5, but jQuery honors them: jQuery Data API.
You can use data-* attributes.
<a href="div1" data-id="div1">link1</a>
<a href="div2" data-id="div2">link2</a>
<a href="div3" data-id="div3">link3</a>
And you can access the value from element.dataset.id
Edit: If you want to support older browsers too, you can use rel
attribute.
精彩评论