Skip to content

Try our new Crash Courses!

Become a member using the button below to hide this banner and gain access to our new Crash Courses.

Modify text in element – JavaScript

Summary

element.textContent = 'Hello world';

Details

To modify the text inside an element, use the textContent property.

First, make sure you’ve selected an element in your JS file.

let element = document.querySelector('#my-element');

Then use the textContent property to add text or change the text.

let element = document.querySelector('#my-element');
element.textContent = 'Hello world';

Demo

Exercises

Recreate the JS code from the Demo section in your JS file. Then try customizing the text for the textContent property.

Back to: JavaScript Reference > JS DOM