Skip to content

Instantly share code, notes, and snippets.

@dSalieri
Last active August 23, 2021 17:06
Show Gist options
  • Save dSalieri/53ce1adf52289bd353eafbe2b4dd36b9 to your computer and use it in GitHub Desktop.
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
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