Reputation: 59
I want to hide a button after it has been clicked.
HTML:
<div id="welcomeDiv" style="display:none;" class="answer_list">
WELCOME
</div>
<input type="button" name="answer" value="Show Div" onclick="showDiv()" />
JavaScript:
function showDiv() {
document.getElementById('welcomeDiv').style.display = "block";
}
In this fiddle you can see that the button is still visible after having been clicked: http://jsfiddle.net/rathoreahsan/vzmnJ/
How can I hide the button after click?
Upvotes: 0
Views: 402
Reputation: 36609
Try this:
function showDiv(elem) {
elem.style.display = 'none';
document.getElementById('welcomeDiv').style.display = "block";
}
<div id="welcomeDiv" style="display:none;" class="answer_list">WELCOME</div>
<input type="button" name="answer" value="Show Div" onclick="showDiv(this)" />
Upvotes: 4