Possible Duplicate:
Custom attributes - Yay or nay?
Hello, it might be a very basic question but I wonder if are there any implications to set custom attributes to HTML tags... in terms browsers compatibility, SEO, complainants etc.
thanks
Possible Duplicate:
Custom attributes - Yay or nay?
Hello, it might be a very basic question but I wonder if are there any implications to set custom attributes to HTML tags... in terms browsers compatibility, SEO, complainants etc.
thanks
In general, if you set your own attributes on HTML elements, you will have to build a browser that understands those attributes (and make sure that your users have the browser).
Well, your code won't validate but I doubt it will really cause much of a problem. What is the purpose of these custom attributes and could they be replicated with the HTML5 data attribute?
(No "HTML5 isn't ready" responses please)
Only problems would come with validation. You can add as many attributes as you want, but they won't pass validation tests.
As someone else said, they won't be recognized by default, you would probably have to write your own javascript or something to be able to read them.
If you're using HTML5, you are absolutely allowed to add custom attributes to your tags. Here's an article on the subject: http://ejohn.org/blog/html-5-data-attributes/
If you're stuck using an older HTML or xhtml version then by rights you shouldn't be adding attributes. However for the most part the browser will accept it. You should test comprehensively though, as it's outside the spec so different browsers may behave differently.
In xhtml, you definitely can't add attributes, since it would break the document definition and won't validate. However (as stated in the article I linked earlier), you can add them using a different namespace if you need to.
In most cases where you are adding attributes to HTML that isn't standard markup or CSS you want to store data for JavaScript to have for interactions. Look into the jQuery.data()
capabilities and that may give you what you're looking for.