Skip to content

Commit

Permalink
<details> toggle event improvements (#33750)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-we committed May 25, 2024
1 parent 9f959a3 commit 630c591
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions files/en-us/web/api/htmldetailselement/toggle_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ This event is not cancelable and does not bubble.

Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js
```js example-good
addEventListener("toggle", (event) => {});

ontoggle = (event) => {};
```

```html example-bad
<details ontoggle="console.log(this.open)" open>...</details>
```

> **Note:** In the example above the event listener will be called once without any user interaction because the `open` attribute is set. Using event handlers like this [is discouraged](/en-US/docs/Web/HTML/Attributes#event_handler_attributes).
## Event type

A generic {{domxref("Event")}}.
A {{domxref("ToggleEvent")}}. Inherits from {{domxref("Event")}}.

{{InheritanceDiagram("ToggleEvent")}}

## Examples

Expand Down

0 comments on commit 630c591

Please sign in to comment.