views:

20

answers:

2

I have an element where I'm already using the rel attribute, but I would also like to add another attribute that I'll be using in JavaScript.

<a href="/" rel="blah" foo="bar">Link</a>

Is it alright to add other attributes? Or is there a better option?

+2  A: 

I would use html5 data- attributes. Even if you are not using html 5 you can be sure your work will still work and is futureproof.

e.g

<li class="user" data-city="Boston" data-food="Bacon">
redsquare
Thxs, exactly what I needed. I should be building HTML5 websites anyway :)
Darryl Hein
A: 

It's okay to add new attributes through JavaScript, but if you add them directly in the source, your markup won't validate. If it's just one more attribute you need, there's a rev attribute just like rel.

casablanca
Adding arbitrary attributes could lead to issues if the users browser uses that attribute for some bit of logic or ui. You would need to make sure the attribute was unique. HTML5 provides the data- prefix which solves this issue.
Pullets Forever