HTML event attribute ontoggle








The ontoggle attribute event is triggered when opening or closing the <details> element.

What's new in HTML5

The ontoggle attribute is new in HTML5.

Syntax

<details ontoggle="script">

Supported Tags

<details>

Browser compatibility

details Yes No No Yes Yes




Example

<!DOCTYPE html>
<html>
<body>
<!--  w  w w .  ja v  a2s.c o  m-->

<details ontoggle="myFunction()">
    <summary>Open the summary</summary>
    <p>this is a test.</p>
</details>

<script>
function myFunction() {
    console.log("The ontoggle event occured");
}
</script>

</body>
</html>

Click to view the demo