Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140788

innerText vs innerHtml vs label vs text vs textContent vs outerText

$
0
0

I have a dropdown list which is populated by Javascript.

Whilst deciding what should be the default value to show on load, I realised that the following properties showed exactly the same values:

  • innerText
  • innerHtml
  • label
  • text
  • textContent
  • outerText

My own research shows bench marking tests or comparisons between a few of them, but not all.

I can use my own common sense and choose 1 or the other as they provide the same result, but, I'm concerned this is not going to be a good idea if the data were to change.

My findings are:

  • innerText will show the value as is and ignores any HTML formatting which may be included
  • innerHTML will show the value and apply any HTML formatting
  • label appears to be the same as innerText, so I can't see the difference
  • text appears to be the same as innerText but the jQuery shorthand version
  • textContent appears to the same as innerText but keeps formatting (such as \n)
  • outerText appears to be the same as innerText

My research can only take me so far as I can only test what I can think of or read what is published, can any one confirm though if my research is correct and if there is anything special about label and outerText?


Viewing all articles
Browse latest Browse all 140788

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>