From the course: JavaScript: Enhancing the DOM

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Using text content modifiers

Using text content modifiers

From the course: JavaScript: Enhancing the DOM

Start my 1-month free trial

Using text content modifiers

There's a number of properties that allow you to change the content related to a node as HTML. The most common and oldest is innerHTML. It also has the most support in browsers. In newer browsers, you can also use outerHTML, which will include any tags within the current node. There's also a new function that lets you insert some additional HTML within a specified node. It's called InsertAdjacentHTML and it takes two parameters. First, a string that determines the insertion point and then the HTML. So, let's take a look at these. I want to switch over to my document, and pull up the developer tools and the console. So, I'll start by creating a variable called mynode, and then targeting a node in the DOM. Now this time, I'm going to target the text node right here that has this article. So, I'm going to hit this magnifying glass and click right here on this headline. That tells me the path to that node, which I know is going to be an article with the ID about the event. So, let me…

Contents