Reputation: 451
I have created a navbar with Jquery and HTML5, and for usability I decided to get a variable directly in the HTML like that
<nav class="mainNav" breakpoint="768">
I saw it is needed to add "data-" before my custom attribute. So the question is, is it valid to process like this, and is there a problem with XHTML/XML ? Is it a problem if the XHTML/XML is not valid ?
Thanks.
Upvotes: 1
Views: 65
Reputation: 13949
Well, you "can" go this way. It will make your HTML invalid, but in practice, it's not really a big deal, only purists will complain, and most browser will just render the page normally. Also it's not really clear what you want. Do you just want it to be HTML valid, or also XHTML valid ? XHTML is probably the biggest failure of W3C, so if you just need to make a classic webpage, html5 compliance is more than enough.
However, the "data-" is now in the HTML specifications. So I encourage you to use this. Not only your page will become truly valid, but you'll also be able to use convenience methods like document.getElementById('myID').dataset.breakpoint
!
EDIT Whatever you do, you can use The W3C Validator to check error/ get tips
Upvotes: -1
Reputation: 1348
No it's not. You can use like data-breakpoint="768"
but no like breakpoint="768"
NOTE: It is not only about standards and rules, HTML parser will need to work much harder if he deals with something that is not standards compliant.
Upvotes: 4