Javascript DOM ontoggle Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

object.addEventListener("toggle",
       myScript);

This example uses the addEventListener() method to attach a "toggle" event to a details element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Open the details.</p>

<details id="myDetails">
<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>//from www  .ja  va  2 s  .co m
<p id="demo"></p>
<script>
document.getElementById("myDetails").addEventListener("toggle", myFunction);

function myFunction() {
  document.getElementById("demo").innerHTML = "The ontoggle event occured.";
}
</script>

</body>
</html>
Bubbles: No
Cancelable: No
Event type: Event
Supported HTML tags: <details>



PreviousNext

Related