Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

textContent

The textContent property of the Element object returns or changes the plain text content inside of the element. Any HTML tags in the content will be ignored and only plain text is returned. In order to return HTML markup and text content, use the innerHTML property instead.

Syntaxelement.textContent
<p id="p1">This is my <b>paragraph</b> content.</p> <script> alert( document.getElementById("p1").textContent ); </script>

Change the text content

document.getElementById("p1").textContent = "New text content";

Append (add to the end)

document.getElementById("p1").textContent += " More text content.";

Prepend (add to the beginning)

var existing = document.getElementById("p1").textContent; document.getElementById("p1").textContent = "Prepended text content. " + existing;

JavaScript

Properties

bodycalleeclosedcookiedocumentdropEffecteffectAllowedfilesframeElementframeshistoryInfinityinnerHeightinnerHTMLinnerWidthlengthlocationlocationbarnameNaNnavigatornullopenerouterHeightparentprototypescreenstatetextContentundefined