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.

Targeting the attributes property

Targeting the attributes property

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

Start my 1-month free trial

Targeting the attributes property

Another way you can get access to attributes inside your nodes is through the attributes property. Once you retrieve this property, its values can be accessed in a number of ways. So you can look for them by numeric index, also by named index or dot notation. So, let's take a look at how that works. So here's my file, I'm going to get into the console, and I'll create a variable that accesses a specific node instance. Let's test my node, and it has the first image, and that is this image right here. So, we can get to all the attributes inside this image by using my node and then type in attributes. When we hit Enter, you see that we have a node map, and it's a list of all the attributes in numeric order. Now this is a pretty interesting object, because it has attributes of both array elements, and also objects. So, you can get to the source attribute in a number of ways. It's the first attribute, so it would have an index of zero. And that works like an array. You can also get to it…

Contents