Last active
August 23, 2021 17:06
-
-
Save dSalieri/53ce1adf52289bd353eafbe2b4dd36b9 to your computer and use it in GitHub Desktop.
It's a little bit different toggle function, it toggles attribute in HTMLElement and sets value for it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toggleAttribute(el, name, value) { | |
if(!(el instanceof HTMLElement)) return null; | |
if (el.hasAttribute(name)) { | |
el.removeAttribute(name); | |
return false; | |
} else { | |
el.setAttribute(name, value != null ? value : ""); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment