Method _.Node.text
Pulls the plaintext contnets of an element in a cross browser consistent manner. This means that all whitespace is condensed to a single character and any leading/trailing whitespace is stripped off.
The whitespace normalization is done to address the fact that legacy IE's Element.textContent
doesn't return quite the same value as what modern browsers return when using Element.innerText
.
- Calling Convention:
-
_.Node.text(Element)
- Parameters:
-
- Element
- The Element to pull the text contents of.
- Returns:
- All text inside the Element with whitespace compressed to single spaces and any leading/trailing whitespace trimmed off.
Example
HTML
<div id="test">
This is a test
-
<span>As is this</span>
</div>
JavaScript
Console.log(
'"' + _.Node.text(document.getElementById('test')) + '"'
);
Output
"This is a test - As is this"