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.
Using text content modifiers
From the course: JavaScript: Enhancing the DOM (2013)
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…
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
-
-
-
-
-
(Locked)
Changing HTML attributes5m 25s
-
(Locked)
Working with restricted attributes2m 49s
-
(Locked)
Detecting data attributes3m 29s
-
Controlling classes with the HTML5 classList3m 21s
-
(Locked)
Targeting the attributes property1m 24s
-
(Locked)
Using text content modifiers3m 42s
-
(Locked)
Modifying elements as text2m 15s
-
(Locked)
-
-
-