From MDN :
Internet Explorer introduces the element.innerText element. The intent is pretty much the same as [textContent] with a few differences:
Please note: while textContent gets the contents of all elements, including <script> and <style> elements, basically equivalent IE-specific property, innerText does not support.
innerText also knows the style and will not return the text of hidden elements, whereas textContent will.
Since innerText knows the CSS style, it invokes reflection, while textContent does not.
Therefore, innerText will not include text that is hidden by CSS, but textContent will.
innerHTML returns HTML as its name indicates. Quite often, people use innerHTML to retrieve or write text inside an element. Instead, use textContent. Since the text is not parsed as HTML, it probably has better performance. In addition, this avoids the attack of the XSS vector.
In case you missed this, let me repeat it more clearly: do not use .innerHTML unless you specifically intend to embed HTML in an element and take the necessary precautions to make sure that the embed HTML cannot contain malicious content. If you want to insert text, use .textContent or if you need to support IE8 and earlier, use the function detection function to disable between .textContent and .innerText .
The main reason that there are so many different properties is because different browsers initially had different names for these properties, and still there is no full cross-browser support for all of them. If you are using jQuery you should stick with .text() as this is intended to smooth out differences between browsers. *
For some of the others: outerHTML is basically the same as innerHTML , except that it includes the start and end tags of the element to which it belongs. I generally can not find much description of outerText . I think this is probably an obscure legacy and should be avoided.
JLRishe Jun 26 '14 at 10:27 2014-06-26 10:27
source share