As the title says. I can't seem to see the difference between the two, and I can't seem to see the point of the second argument for toggle.
Can someone explain to me?
There is no difference; the second argument to toggle
is to make this kind of thing more convenient:
if (hide) {
el.classList.add('hidden');
} else {
el.classList.remove('hidden');
}
as:
el.classList.toggle('hidden', hide);
https://dom.spec.whatwg.org/#interface-domtokenlist :
If force is not given, "toggles" token, removing it if it’s present and adding it if it’s not. If force is true, adds token (same as add()). If force is false, removes token (same as remove()). Returns true if token is now present, and false otherwise.
I think the spec is clear enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With