+ 1

Why and when we can use " nodevalue" in html

26th Dec 2017, 4:46 PM
Muhmd Ezz
Muhmd Ezz - avatar
3 odpowiedzi
+ 4
Here is a good explanation from Stackoverflow.com: https://stackoverflow.com/questions/21311299/nodevalue-vs-innerhtml-and-textcontent-how-to-choose Summary - nodeValue is a little more confusing to use, but faster than innerHTML. - innerHTML parses content as HTML and takes longer. - textContent uses straight text, does not parse HTML, and is faster. - innerText Takes styles into consideration. It won't get hidden text for instance. innerText didn't exist in firefox until FireFox 45 according to caniuse but is now supported in all major browsers. By: https://stackoverflow.com/users/438819/peterfoldi
26th Dec 2017, 5:39 PM
David Carroll
David Carroll - avatar
+ 2
I've never used it and based on examples I've seen innerHTML is what I use instead. Since I'm curious, I'm going to ping JavaScript on discord to see if someone else might respond.
26th Dec 2017, 5:30 PM
John Wells
John Wells - avatar
+ 2
We would always use innerText for getting text from a element. One of the reason we would use nodeValue only is to get text from an element but exclude its child elements text. for example: <div id="txt">Show this <span>ignore this</span></div> <script> var txt = document.getElementById("txt"); alert(txt.childNodes[0].nodeValue); alert(txt.innerText); The nodeValue only return the text without span text whereas innerText return all the text including span text. https://code.sololearn.com/WB91QIGd48wo/?ref=app
27th Dec 2017, 1:00 AM
Calviղ
Calviղ - avatar