课程: JavaScript Essential Training

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Attributes

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.…

内容