Advertisement

Google Ad Slot: content-top

JS Modify Content Dom

~1 min read · JS
On this page

In JavaScript, modifying content in the DOM allows you to dynamically change the text, HTML structure, or even remove content in a webpage. Below are the common methods to manipulate content in the DOM:


textContent:

  • Updates or retrieves the text inside an element.
  • Strips any HTML tags and treats everything as plain text.
Example
Existing text
Try it yourself

innerHTML:

  • Sets or retrieves the HTML content inside an element.
  • Allows you to insert HTML tags as well.
Example
Existing text
Try it yourself

outerHTML:

  • Sets or retrieves the HTML of the element itself, including the element tag.
Example
Existing text
Try it yourself

value:

  • Get value from input element
Example

value in js

Open console in browser then you will see output

Try it yourself