Method: 1. Bind the click event to the button element and specify the event processing function; 2. In the event processing function, use the style attribute and display attribute to set the button to disappear after clicking the button. The syntax is "button Element object.style.display="none"".
The operating environment of this tutorial: Windows 10 system, HTML5 version, Dell G3 computer.
The Style object represents a separate style statement. A Style object can be accessed from the document or element to which the style is applied.
Syntax for using the Style object attribute:
document.getElementById("id").style.property="值"
The display attribute specifies the type of box that the element should generate.
When the value of the attribute is set to none, this element will not be displayed.
The example is as follows:
<html> <head> <script type="text/javascript"> function setStyle() { document.getElementById("anniu").style.display="none"; } </script> </head> <body> <button onclick="setStyle()" id="anniu">按钮</button> </body> </html>
Output result:
Recommended tutorial: "html video tutorial"
The above is the detailed content of How to set the button to disappear after clicking it in html5. For more information, please follow other related articles on the PHP Chinese website!