Execute a JavaScript when a <details> element is opened or closed:
<!DOCTYPE html> <html> <body> <p>Open the details.</p> <details ontoggle="myFunction()"> <summary>Copyright 2020-2024.</summary> <p> - by java2s.com. All Rights Reserved.</p> <p>All content and graphics on this web site are the property of the java2s.com.</p> </details>// w w w. j a v a 2 s.c o m <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "The ontoggle event occured"; } </script> </body> </html>
The ontoggle event occurs when the user opens or closes the <details> element.
The <details> element specifies additional details that the user can view or hide on demand.
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Supported HTML tags: | <details> |