Cybrix
Cybrix

Reputation: 3318

What happens if you use custom attribute in a HTML tag?

this question isn't related to jQuery itself but I found a plugin named Metadata found there and one of the example uses custom tag attribute: <li data="{some:'random', json: 'data'}">...</li>.

Q: Is that cross-browser? Will this fail when validating markup?

Thanks.

Upvotes: 5

Views: 430

Answers (2)

Darko
Darko

Reputation: 38860

The browser wont care. Most (if not all browsers) just ignore illegal attributes. If you try to validate it, it WILL fail however. What you need to do is figure out if you're OK with this. If you are just keep the doctype. If not change the doctype. One thing to note is that even if you keep the doctype and the illegal attribute it wont impact your site in any way that it doesnt validate.

In fact your markup might still validate if the data attribute is being added after the page loads - which means that at the point the validation occurs the data attribute wont be there.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798516

The browser won't care, since very, very few browsers actually validate the HTML. It will fail if you try to treat it as XHTML though, since it isn't valid XHTML.

Upvotes: 3

Related Questions