Span.innerHTML returns text, but Span.value returns undefined?

I have a function that fills the pages with something like this

<span id="span_title_'+result_no+'">'+title+'</span> 

and then I have another function that has this:

  document.getElementById("span_title_"+which_table).innerHTML="asg"; alert(document.getElementById("span_title_"+which_table).value); 

It is strange that the first (innerHTML) call works fine, the second, warning, gives me " undefined "

Any idea why this is?

+6
source share
2 answers

<span> DOM elements do not have a value property. Use innerHTML to read the content.

+15
source

span does not have an attribute named "value" only innnerHTML, you must use innerHTML for the second call.

+1
source

Source: https://habr.com/ru/post/890934/


All Articles