The DOM innerText Property is used to set or return the text content of a specified node and its descendants. This property is very similar to the text content property but returns the content of all elements, except for <script> and <style> elements.
Syntax: It is used to set the innerText property.
node.innerText = text
Return Value: It returns a string value that represents the text content of the element along with its descendants.
Example 1: In this example, we will see DOM innerText Property
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM innerText Property
</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM textContent Property</ h2 >
< button id = "geeks" onclick = "MyGeeks()" >
Submit
</ button >
< p id = "sudo" ></ p >
< script >
function MyGeeks() {
let text =
document.getElementById("geeks").innerText;
document.getElementById("sudo").innerHTML = text;
}
</ script >
</ body >
</ html >
|
Output:
Example 2: In this example, we will see DOM innerText Property
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM innerText Property
</ title >
</ head >
< body >
< center >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM innerText Property</ h2 >
< p id = "geeks" style = "font-size:20px;" >Hello Geeks!</ p >
< button onclick = "MyGeeks()" >
Submit
</ button >
< script >
function MyGeeks() {
document.getElementById("geeks").innerText =
"Welcome to GeeksforGeeks!";
}
</ script >
</ center >
</ body >
</ html >
|
Output:
Supported Browsers: The browser supported by DOM innerText property are listed below:
- Google Chrome 1.0 and above
- Edge 12.0 and above
- Internet Explorer 5.5 and above
- Firefox 45.0 and above
- Opera 9.6 and above
- Safari 3.0 and above
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
15 Jun, 2023
Like Article
Save Article