views:

109

answers:

5

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

A: 

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).

martin jakubik
That's pretty extreme isn't it? I've used custom attributes to assist in Javascript development and have never even thought about building my own browser.
John Bledsoe
@John I think a better answer would be that for your HTML (before HTML5) to validate, you'll have to write your own DTD
Yi Jiang
It is somewhat extreme and kinda scary to someone just starting out to programming. The question is asking about attributes but is really about data in HTML. Maybe suggest a way to get the results even though the lingo isn't right, that would be of good use to him and all of us.
Liam
Yup, I guess it is extreme. Although all I meant by "browser" was "code that reads the html". Where that "code" could just be your javascript. But I wasn't clear.
martin jakubik
A: 

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)

ILMV
A: 

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.

Tom
+1  A: 

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.

Spudley
A: 

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.

http://api.jquery.com/jQuery.data/

Liam