Does any one know innerText alternative of a span in mozilla? My span is
<span id='cell1'></span>
and the javascript is
document.getElementById('cell1').innerText = 'Tenelol';
But Mozilla is not supporting this!!
textContent gets the content of all elements, including <script> and <style> elements. In contrast, innerText only shows "human-readable" elements. textContent returns every element in the node. In contrast, innerText is aware of styling and won't return the text of "hidden" elements.
javascript - 'innerText' works in IE, but not in Firefox - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
The Differences Between The innerHTML property returns: The text content of the element, including all spacing and inner HTML tags. The innerText property returns: Just the text content of the element and all its children, without CSS hidden text spacing and tags, except <script> and <style> elements.
Note: Unlike innerHTML, textContent has better performance because its value is not parsed as HTML. For that reason, using textContent can also prevent Cross-Site Scripting (XSS) attacks. Unlike innerText, textContent isn't aware of CSS styling and will not trigger a reflow.
innerText
is a proprietary IE thing. The W3C defines textContent
as the official property.
An easy way is to exploit the ||
logical operator and its short circuiting nature, as well as JavaScript returning the last evaluated value in a condition (most times the truthy operand).
var body = document.body,
text = body.textContent || body.innerText;
jsFiddle.
(Note in the fiddle I checked for the innerText
first. This was only because most people on here do not use IE. IRL, check for textContent
first, and fallback to innerText
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With