How to Change the DOM Elements within JavaScript


show more Now that you know how to access DOM elements, you can change or edit those web page elements using JavaScript. Learn two methods to work with HTML element attributes (getAttribute and setAttribute) and access content insider with innerHTML, a simple JavaScript method. show less
please wait ...

Changing DOM elements

Using JavaScript to read information about the nodes on our page is all very well, but we really want to be able to change it. Step one for doing this is always going to be get the element. You need that variable to be a handle on the element. Sure, we know that we've got elements, and we also have attributes and text nodes, but it's the element that comes first. Attribute nodes and text nodes belong to elements. If you're writing HTML, you don't write an attribute by itself. It's the attribute of an element.

So that's what comes first. Step two is okay, then we can change it. The question is, what do you want to change about it? If you were manually editing this code in a text editor, what would you want to do? Do you want to pick an attribute and change it or add a new attribute? Do you want to change a link inside a heading? Do you want to add a whole bunch of new elements inside a div or inside a list? Well, we can do all of that, but let's talk about changin...

Changing DOM elements
Video duration: 5m 42s 5h 31m Beginner

Viewers:

Now that you know how to access DOM elements, you can change or edit those web page elements using JavaScript. Learn two methods to work with HTML element attributes (getAttribute and setAttribute) and access content insider with innerHTML, a simple JavaScript method.

Subjects:
Developer Web
Software:
JavaScript
Author:
please wait ...