From the course: JavaScript: Enhancing the DOM
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Changing text and HTML content
From the course: JavaScript: Enhancing the DOM
Changing text and HTML content
- [Instructor] This is a very exciting module. Yes, I'm saying that again, but this is the module where you'll learn how to change the text and HTML content of elements using JavaScript. This is where things get really dynamic and fancy as you can dynamically update your webpage in response to user actions. No need to wait any longer. Let's start with changing the text and HTML content. In order to change an element's text or the HTML inside an HTML element, we will have to select it first. For example, we can use document.getElementById message. To change the text inside an element, we can use the innerText property, for example, documents.getElementById message .innerText, and then set it to equal Hello world. This changed the text of the element with the ID message to Hello World. Let's do that in practice. Here, we have something relatively new. This is a user dashboard and on line 15 we have a update button, but I'm having a special attribute. I'm saying onclick equals…
Contents
-
-
-
-
-
-
(Locked)
Changing text and HTML content2m 51s
-
(Locked)
Changing values of input elements4m 35s
-
(Locked)
Manipulating attributes and data attributes2m 1s
-
(Locked)
Working with classes2m 21s
-
(Locked)
Inline styles with JavaScript2m 9s
-
(Locked)
Challenge: Shapeshifter50s
-
(Locked)
Solution: Shapeshifter47s
-
(Locked)
-
-
-
-
-
-