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.
Modifying elements as text
From the course: JavaScript: Enhancing the DOM (2013)
Modifying elements as text
Although you can modify the content of notes as HTML text with the inner HTML property, there's a few other ways of doing it. However there's some really big browser issues here. Let's take a look anyways. You can use the innerText property to get just the text of the node. However you have to use textContent if you're using Firefox. That means that if you want to access just the text of a node, you're going to have to do something like this in JavaScript. If the text exists within the inner text property, then you can set your text to that. Otherwise you'll have to use the Firefox version. So let's take a look at this in the dom. We'll start by getting an element from the dom, we'll place it in a variable called my node. So right now we're targeting this section right here called about the event. If you want to, you can click on the magnifying glass and click on that headline. Let me go ahead and hit enter and test out my node. And sure enough, it has the whole article, now if we do…
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)
-
-
-