From the course: JavaScript Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Attributes - JavaScript Tutorial
From the course: JavaScript Essential Training
Attributes
- [Instructor] JavaScript can be used to modify the attributes of any elements. The attributes are stored in the attributes property, it can be accessed directly by calling it. One thing worth noting here is the attributes property returns a different type of data from the class name and class list properties. What we get is a named node map and it is not an array. So we can't use array methods on it. There's a simple reason for this. An attribute is a more complex piece of data, it has a key and a value and we need to be able to manipulate just the key or just the value or both at any time and a simple array wouldn't do that. Let's look at the attributes property first. So I'll select this image here 'cause I know it has attributes and has a source attribute and an alt attribute. Then we can call it in using JavaScript and look at what that attributes property contains. What I get in return is a named node map.…
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
-
-
-
-
-
-
-
DOM: The Document Object Model4m 7s
-
(Locked)
Access elements with querySelector methods6m 6s
-
(Locked)
Access elements using older methods3m 45s
-
(Locked)
Practice: Find an element1m 29s
-
(Locked)
Modifying element classes4m 53s
-
(Locked)
Attributes4m 13s
-
(Locked)
Inline style3m 52s
-
(Locked)
Practice: Modify classes and attributes, and styles1m 36s
-
(Locked)
Add DOM elements5m 25s
-
(Locked)
Challenge intro: Create elements1m 17s
-
(Locked)
Solution: Create elements3m 35s
-
-
-
-
-
-
-