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

Modifying elements as text

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

Start my 1-month free trial

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…

Contents