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.

Working with restricted attributes

Working with restricted attributes

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

Start my 1-month free trial

Working with restricted attributes

The quickest way to work with element attributes is to use the dot notation. That's not always convenient because sometimes attribute names like class or for can be restricted in JavaScript. But there's another way of doing it. JavaScript provides a few functions for dealing with attributes. So, for example, you can use the getAttribute method to get the value of any attribute in an element. If you set attribute you can set the value of an existing attribute. You can check to see if an element has an attribute function. Finally, you can remove an attribute with the delete attribute function. So let's take a look at these in a document. Here's our web page. I'm going to go over to the registration page, and I'm going to pull up the console, Cmd+Option+I, Ctrl+Alt+I on a PC, and then hit escape. And then I'm going to create a variable called My Node, and pass it, and element in my DOM. (SOUND) So, I'm going to test that out. And you can see that I have the first label which has the word…

Contents