Reputation: 6217
I am needing to attach a value to an <a>
element that will be handled in jQuery. Basically, I am aware of the data-
attribute prepended to whatever name I want to give it, but I'm not sure this is the best for (X)HTML, as the software I am coding for is declaring DTD's within the tag, so it would not pass (X)HTML 5.0 validation, as I'm not able to change this to exclude the DTD's.
My question is, can I just use the <a>
elements tag
attribute to hold the URL links that jQuery will grab using the following code: $(this).attr('tag');
The href attributes value is set to: javascript:void(0);
because the actual URL triggers an AJAX event and is not an actual page that one should be browsing to in their browser, as it just performs an action to be taken when clicked on.
I'm not entirely sure what the <a>
elements tag
attribute is to be used for, but am wondering if this is the best known attribute to use to be able to be valid (X)HTML in both HTML 4 and 5?
Upvotes: 0
Views: 219
Reputation: 943537
My question is, can I just use the
<a>
elementstag
attribute
There is no tag attribute in HTML. So that will have all the problems of data-*
but without the future support.
If you want to store arbitrary data in HTML 4/XHTML 1 then the best attribute to use is probably class
.
The href attributes value is set to:
javascript:void(0);
because the actual URL triggers an AJAX event
Don't do that. Use a real (working) URI, and add a JavaScript event handler that prevents the default behaviour if it succeeds. If the URI contains the data you need for your JS to run, then all the better as you can extract it from the href
attribute.
Upvotes: 2