Reputation: 14834
So suppose I have this tag
<a href=""></a>
and then I make up some non-standard attribute
<a lol="haha" href=""></a>
If you ask why, well so that I can conveniently use that made up attribute in my javascript...
My question is...is there any possible negative repercussion of doing this....is there any good reason why I shouldn't be doing this?
Upvotes: 2
Views: 214
Reputation: 35253
There is an attribute family that was made exactly for that: data-*
. You should use
<a data-lol="haha" href="#"></a>
That will be valid and save you from any headaches. A custom attribute might conflict with a predefined one (or one that doesn't exist yet), or cause problems in non-compliant parsers.
Upvotes: 1
Reputation: 83358
Browsers will almost universally handle custom attributes. And when I say universally, I mean even IE6.
Of course the standard way to do that is with:
<a data-lol="haha" href=""></a>
Which, since you've tagged with jQuery, I'll mention can be read (even in IE6) with
$("a").data("lol");
Upvotes: 7
Reputation: 298106
You can do this with HTML5:
<a data-lol="haha" href=""></a>
As for the downsides, I will say this: standards are made for a reason. Just because it looks like it works won't mean that it will work in the future.
Upvotes: 1
Reputation: 5544
I'd recommend using the HTML data- attribute HTML 5 data- Attributes
Upvotes: 1