Horje
HTML ontoggle Attribute

Definition and Usage

The ontoggle attribute fires when the user opens or closes a <details> element.

The <details> element specifies additional details that the user can view or hide on demand.


Applies to

The ontoggle attribute is part of the Event Attributes, and can be used on the following element:

Elements Event
<details> ontoggle

Browser Support

The numbers in the table specify the first browser version that fully supports the event attribute.


How to Execute a JavaScript when a <details> element is opened or closed - HTML ontoggle Attribute

Click on Arrow to Open the details System HTML Code.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<p>Open the details.</p>

<details ontoggle="myFunction()">
<summary>Copyright 1999-2014.</summary>
<p> - by Refsnes Data. All Rights Reserved.</p>
<p>All content and graphics on this web site are the property of the company Refsnes Data.</p>
</details>

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

</body>
</html>

Output should be:

How to Execute a JavaScript when a <details> element is opened or closed - HTML ontoggle Attribute




html ontoggle attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference