![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML ontoggle Event Attribute
The HTML ontoggle event attribute is triggered when a user opens or closes the <details> HTML element in an HTML document.
Syntax
Following is the syntax −
<details ontoggle=”script”>Content</details>
Let us see an example of HTML ontoggle event Attribute −
Example
<!DOCTYPE html> <html> <head> <style> body { color: #000; height: 100vh; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat; text-align: center; padding: 20px; } </style> </head> <body> <h1>HTML ontoggle Event Attribute Demo</h1> <details ontoggle="toggleFn()"> <summary>Hi! I'm summary element</summary> <p>This is a paragraph with some dummy content.</p> </details> <script> function toggleFn() { document.body.style.background = "linear-gradient(45deg, #8BC6EC 0%, #9599E2 100%) no-repeat"; document.body.style.color = "#fff"; } </script> </body> </html>
Output
Now try to open the details HTML element to observe how ontoggle event attribute works.
Advertisements