Skip to content

Instantly share code, notes, and snippets.

@DenisDov
Last active August 7, 2020 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisDov/aeb57528bfe2a63f793cea563dd896ca to your computer and use it in GitHub Desktop.
Save DenisDov/aeb57528bfe2a63f793cea563dd896ca to your computer and use it in GitHub Desktop.
Vanilla js implementation jquery $(this).addClass('is-selected').siblings().removeClass('is-selected');
const toggleElements = document.querySelectorAll("#table tr");
toggleElements.forEach(el => {
el.addEventListener("click", function () {
this.classList.toggle("is-selected");
// siblings
Array.prototype.filter.call(el.parentNode.children, function (child) {
return child !== el && child.classList.remove("is-selected");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment