From the course: JavaScript: Ajax and Fetch
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Modify element content with vanilla JavaScript - JavaScript Tutorial
From the course: JavaScript: Ajax and Fetch
Modify element content with vanilla JavaScript
- [Narrator] Selecting form elements is no different from selecting other DOM elements. You can use querySelector(), querySelectorAll(), or any of the older, more specific methods to select any element in the DOM. But getting or setting content from non-form elements involves a different set of properties than the value property that you use with form elements. Both textContent and innerHTML allow you to get and set text content. It's best to use textContent when you only need text but if you're providing a string of HTML to set an element's value you may find innerHTML useful instead. You can also reference any attribute of an element using dot notation. For instance, you use .src for the source attribute of an image tag The one exception is the class attribute which requires you to use class name instead to avoid confusion with the JavaScript class key word. In some design systems, it's common for an element to have multiple class names assigned. So, it can be more convenient to use…
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
-
-
-
-
What is the DOM?3m 19s
-
(Locked)
Select elements with vanilla JavaScript3m 43s
-
(Locked)
Request data in response to an event4m 14s
-
(Locked)
Add an event listener2m 12s
-
(Locked)
Work with JSON data6m 52s
-
(Locked)
Modify form values with vanilla JavaScript4m 58s
-
(Locked)
Modify element content with vanilla JavaScript5m 49s
-
(Locked)
Challenge: Modify the DOM58s
-
(Locked)
Solution: Modify the DOM7m 55s
-
-
-
-
-