Last active
August 7, 2020 09:04
-
-
Save DenisDov/aeb57528bfe2a63f793cea563dd896ca to your computer and use it in GitHub Desktop.
Vanilla js implementation jquery $(this).addClass('is-selected').siblings().removeClass('is-selected');
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
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