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.


<details ontoggle="script">

Supported Tags


Browser compatibility

details Yes No No Yes Yes


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

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

function myFunction() {
    console.log("The ontoggle event occured");


Click to view the demo