Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  54] [ 5]  / answers: 1 / hits: 18395  / 13 Years ago, fri, september 9, 2011, 12:00:00

How can I detect when a details element is opened or closed in Javascript? Other than attaching a listener to the click function and checking if the open attribute is set or not.


More From » html

 Answers
13

You can use the toggle event:





var details = document.querySelector(details)

details.addEventListener(toggle, function() {
details.firstChild.textContent = done
})

<!doctype html>
<details>
<summary>toggle event</summary>
</details>




[#90182] Thursday, September 8, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
havenbilliec

Total Points: 324
Total Questions: 106
Total Answers: 94

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;