Difference between “.innerHTML” and “.value” in JS

value refers to the value of an input element (or textearea)

<input value="hello world">

value would be "hello world" (or any value typed inside)


innerHTML refers to the contents inside an HTML element.

<div>
  <span class="hello">
     All tags and their children are include in innerHTML.
  </span>
  All this is part of innerHTML.
</div>

innerHTML of the div tag would be the string:

  '<span class="hello">
     All tags and their children are include in innerHTML.
  </span>
  All this is part of innerHTML.'

Leave a Comment