4 ms·
Oh boy, this is an article from April 2015. I had to look this ( innerText vs textContent) up yesterday and MDN had a much clearer explanation. "The innerText
by senthil_rajasek 4y ago
Oh boy, this is an article from April 2015.
I had to look this ( innerText vs textContent) up yesterday and MDN had a much clearer explanation.
"The innerText property of the HTMLElement interface represents the rendered text content of a node and its descendants."
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement...
- thomasahle 4y agoAn example: HTML: <div id="example"> <p style="display: none;">Hidden text</p> <p>Visible text</p> </div> Javascript: const exampleDiv = document.querySelector('#example'); console.log(exampleDiv.innerText); // "Visible text" console.log(exampleDiv.textContent); // "Hidden textVisible text"
- hgsgm 4y agodisplay:none != visibility:hidden
- tomjakubowski 4y agoThat's true. I'm not sure what you mean though; whether one makes the inner div display: none or visibility: hidden, it doesn't appear to make a difference to the values of innerText vs. textContent
- 6510 4y agoI think he means something like:<p style="display: none;">Not Displayed text</p> <p style="visibility: hidden">Hidden text</p> not <p style="display: none;">Hidden text</p>
- raincole 4y agoI think the confusion comes from the fact that you can set it. If it's "rendered result", then everyone, for a sane API design, should assume it's read-only, right?