There's an old deprecated function, document.clear
, that you appear to be clashing with. The current spec defines this as:
The clear(), captureEvents(), and releaseEvents() methods must do nothing.
If you use clear2
for instance, it works as expected.
A better, more modern approach, would be to move your script block after your HTML content, and using an event listener to hook up to the click event, that way you don't even need a function name:
<div id="Div1">
<p>hi</p>
</div>
<div id="Div2">
<p>bye</p>
</div>
<button type="button" id="Refresh">Click</button>
<script>
document.getElementById('Refresh').addEventListener('click', function() {
document.getElementById('Div1').style.display = 'block';
document.getElementById('Div2').style.display = 'none';
});
</script>
In case it's not obvious, we put the script block after the HTML content so that when the script runs during page load, the getElementById('Refresh')
is able to find the <button>
. If the script block was at the top, when the code runs the button wouldn't exist in the page, and it would fail to find it.