Content-Length: 275119 | pFad | http://github.com/roeib/JavaScript-snippets/commit/7b59f88e2a3b5e0412688b78048c13a8883df349

34 Vanilla JS toggle · roeib/JavaScript-snippets@7b59f88 · GitHub
Skip to content

Commit 7b59f88

Browse files
authored
Vanilla JS toggle
1 parent 05953e8 commit 7b59f88

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,5 +474,21 @@ el.addEventListener('click', myClickHandler, {
474474

475475
```
476476
477+
# Vanilla JS toggle
478+
```javascript
479+
const span = document.querySelector("span");
480+
let classes = span.classList;
481+
482+
span.addEventListener("click", function() {
483+
let result = classes.toggle("active");
484+
485+
if (result) {
486+
console.log("active class was added");
487+
} else {
488+
console.log("active class was removed");
489+
}
490+
});
491+
492+
```
477493
478494

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/roeib/JavaScript-snippets/commit/7b59f88e2a3b5e0412688b78048c13a8883df349

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy