I like this solution of toggle. A little bit of head scratching at the calc() function but I get it. But how do I get true or false value out of it, if I wanted to use it in a real application.
Minimalist, an aspiring web dev, comp-sci student, hacker, gamer and a linux enthusiast. I like meeting other nerdy people and seeing what they're doing.
You can use toggle.classList.contains("toggle--sliding"); to check if it's on. Another way is to add a hidden checkbox and then get the value from that.
Or if you're using a framework like React or Vue, clicking on the toggle could change a variable inside of the component and the toggle--sliding class could be added based on whether that variable is true or false. Then you wouldn't even need to check on the DOM, because everything is handled from the JS side (at least by you, the framework does the rest).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like this solution of toggle. A little bit of head scratching at the calc() function but I get it. But how do I get true or false value out of it, if I wanted to use it in a real application.
You can use
toggle.classList.contains("toggle--sliding");
to check if it's on. Another way is to add a hidden checkbox and then get the value from that.Or if you're using a framework like React or Vue, clicking on the toggle could change a variable inside of the component and the
toggle--sliding
class could be added based on whether that variable istrue
orfalse
. Then you wouldn't even need to check on the DOM, because everything is handled from the JS side (at least by you, the framework does the rest).