Document.getElementById (). value return undefined in chrome
<div id="hour" style="display: none">2</div> JavaScript Code:
<script type="text/javascript"> var _h = document.getElementById('hour').value alert(_h); </script> Chrome returns undefined . What is the problem?
The .value property applies to form elements (inputs), not to divs. The easiest way to get the contents of your div element is .innerHTML :
document.getElementById('hour').innerHTML; divs doesn't matter. This is not an entrance.
You want to use innerHTML or innerText / textContent.
document.getElementById("hour").innerText or
document.getElementById("hour").innerHTML