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
From the course: JavaScript: Enhancing the DOM (2013)
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Changing HTML attributes5m 25s
-
(Locked)
Working with restricted attributes2m 49s
-
(Locked)
Detecting data attributes3m 29s
-
Controlling classes with the HTML5 classList3m 21s
-
(Locked)
Targeting the attributes property1m 24s
-
(Locked)
Using text content modifiers3m 42s
-
(Locked)
Modifying elements as text2m 15s
-
(Locked)
-
-
-