I have a function that populates a 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);
The strange thing is the first (innerHTML) call works perfectly, the second one, the alert, gives me "undefined
"
Any idea why this is?
The innerHTML property returns: This element has extra spacing and contains <span>a span element</span>. The textContent property returns: This element has extra spacing and contains a span element.
InnerHTML returning undefined for <code> tag in HTML Of that collection, your code as it is now is not specifying which member of that collection it wants to use. In that case there is a difference in that it returns a live list. But you would still want to specify which you wanted.
People can struggle and complain about innerHTML not working. Such things usually occur because of human error, when strings are not appropriately defined, or there are some mistakes in JavaScript code.
The innerHTML property returns the current HTML source of the element, including any change that has been made since the page was loaded. Do not use innerHTML to set new contents that you have no control to avoid a security risk.
<span>
DOM elements don't have a value
property. Use innerHTML
to read the contents.
span doesn't have attribute with the name "value" only innnerHTML, you should use innerHTML for second call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With