JS - element properties - textContent

revision:


sets or returns the textual content.

top

The property sets or returns the text content of the specified node and all its descendants. It returns "null" if the element is a document, a document type, or a notation.

Syntax:

element.textContent or node.textContent : returns the text content of a node.

element.textContent = text or node.textContent = text: sets the text content of a node.

property value:

text : the text content of the element or node.

example

The text content of the button is:

Click me to change my textual content.

code:
                    <div>
                        <button id="Btn">try it</button>
                        <p>The text content of the button is: <span id="prop"></span></p>
                        <p id="prop1" onclick="propFunction18()">Click me to change my textual content.</p>
                    </div>
                    <script>
                        let text = document.getElementById("Btn").textContent;
                        document.getElementById("prop").innerHTML = text;  
                        function firstFunction() {
                          document.getElementById("prop1").textContent = "I have changed!";
                        }
                    </script>