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

Modify element content with vanilla JavaScript - JavaScript Tutorial

From the course: JavaScript: Ajax and Fetch

Start my 1-month free trial

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…

Contents