Remember that we’re saying the entire text content! For example, if the target element is the <style>, even though the content of this element won’t render on the page, still we get the content if the textContent property was called on such element.
Also, using the textContent property, you can get those text-content that are hidden using CSS.
If we assign a value to the textContent property, it will replace the old content of the target element (including the entire descendants) with this new value.
Note: if you want to get only the text content of an element and its descendants that are rendered on a page, you can use the innerText property for that matter. Also using this property, we can’t get those text-content that are hidden on a page using CSS.
element.textContent; element.textContent = “newValue”;
The value we assign to the textContent property is a string value that will replace the old value of the target element.
The return value of this property is the text-content of the target element as well as the text content of all its descendants (if any).
Note that the value we’ve set for the textContent property contains the <p> element as well!
But when this value rendered on the page, we see the <p> element itself instead of its affect!
Note: use the innerHTML property, if you want browsers to interpret the special keywords in text content we assign to an element as well. (Like the <p> element we’ve put in the text content of the last example).