I'm trying to display a div onclick of a btn by changing the style property of the div. But I can't read the display property of that div. I read somewhere that the code doesn't work because the script tries to get the value before the div has loaded so the script should be triggered after window.onload. How do I make the script work after window has loaded but only when the button has been clicked ?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#hidden-div{
display: none;
}
</style>
<script type="text/javascript">
function showMe() {
var foo = document.getElementById('hidden-div');
alert(foo.style.display); //this gives a blank alert
if(foo.style.display == ''){
foo.style.display = 'block';
}
else {
foo.style.display == 'none';
}
}
</script>
</head>
<body>
<input type="button" id="btn-me" onclick="showMe()">+ clicking here should display the checkboxes</input><br>
<div id="hidden-div">
<input type="checkbox" id="check-1"> Check 1</input>
<br>
<input type="checkbox" id="check-2"> Check 2</input>
<br>
<input type="checkbox" id="check-3"> Check 3</input>
</div>
</body>
</html>