Search⌘ K

Modify an Existing Element

Explore how to dynamically update existing HTML elements using JavaScript. Learn to change element content with innerHTML and textContent, set attributes with setAttribute(), and manage classes via classList for effective DOM manipulation.

The DOM traversal properties can also be used to update elements in the page.

Example page

Let’s view the text on a page using the HTML code below.

HTML content

The innerHTML property can be used to change the content of an element within the DOM. For example, you can add a new language to our list with the code below. We’ll access the ...