views:

151

answers:

4

Is it possible to destroy an html button. If it is clicked because it already served its purpose after clicking.

+2  A: 

Yes, it is possible, by using JavaScript to set its CSS property "display" to "none".

See also Seven ways to toggle an element with JavaScript.

littlegreen
+8  A: 

You can do so with JavaScript:

<button onclick="this.parentNode.removeChild(this)">Label</button>
Gumbo
parent**Node**.
bobince
Ah, damn. Thanks, @bobince.
Gumbo
+1  A: 

Yes, you can disable or hide it. Example:

<input type="button" onclick="this.disabled=true;" />

However, if you do this to the submit button, it may not work properly. The value for the button will not be included in the form data, so if the server looks for the button data to find out what it was that caused the form to submit, it won't find it.

Guffa
Good point about the form data!
Greg B
But this doesn't happen if you hide the button using display = none.
littlegreen
@littlegreen: That may be browser dependant, so I wouldn't rely on it. I remember having problems with Netscape not sending data from invisible fields...
Guffa
+1  A: 

Yes you can do like this:

<input type="button" onclick="this.style.display = 'none';">
Sarfraz