Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  130] [ 4]  / answers: 1 / hits: 61881  / 12 Years ago, tue, may 22, 2012, 12:00:00
<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?


More From » javascript

 Answers
57

The .value property applies to form elements (inputs), not divs. The simplest way to get the contents of your div element is with .innerHTML:



document.getElementById('hour').innerHTML;

[#85432] Monday, May 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
estefanib

Total Points: 508
Total Questions: 104
Total Answers: 83

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;