#What's the difference between InnerText, InnerHTML, and TextContent?

1 messages · Page 1 of 1 (latest)

tawdry knot
#

Hi, everyone! I'm having a difficult time understanding the differences between these three and when I should use them. A lot of the explanations online are kind of too technical for me. Could someone give me a simple explanation?

shut pond
#

Hi Eve. I’ll give it my best shot.

InnerText will return only the text in an element and its children, but will ignore any HTM formatting (ie. It won’t return the html tags and spaces contained within the element).

InnerHtml will return the entire content of an element and its children containing the html tags as well. You can also create an html element utilizing this method, ie. ‘…InnerHtml = <h>Hello, Eve</h>’

TextContent basically does the same as InneText but I believe it also respects your html formatting (though it doesn’t return it).

Hope this helps!

tawdry knot
#

Wow! This really helps. Thank you so much Leo! Really appreciate it. 🙂