From the course: JavaScript: Enhancing the DOM (2013)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Detecting data attributes

Detecting data attributes

From the course: JavaScript: Enhancing the DOM (2013)

Start my 1-month free trial

Detecting data attributes

In an HTML document, a developer can type in any attributes, even if they don't necessarily exist and pretend they're valid HTML. The browsers usually ignore them, but validaters will flag these as not being normal HTML. This is the HTML for the document we've been working with. And if I want to, I can add a coolness attribute here and set it to whatever I want. Now, the browser is probably going to ignore this attribute and not do anything with it, but if I try to validate my document. I want to copy this and I'll switch over to the WC3 validater. And I'll click on the Validate By Direct Input tab, and paste my code right there. And I'll hit the Check button, you could see that it's telling me that there's at least one error there. Let me scroll all the way to the bottom, and notice that it says attribute coolness not allowed on element image at this point. It really means that it doesn't know anything about this new attribute that I just invented. So, thankfully HTML5 provides a way…

Contents