Skip to content

Instantly share code, notes, and snippets.

@pravj
Last active March 12, 2017 16:31
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 pravj/783359e46b0e05b507c1331a51622a8e to your computer and use it in GitHub Desktop.
Save pravj/783359e46b0e05b507c1331a51622a8e to your computer and use it in GitHub Desktop.
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('label')[0].classList.add('button-press');
document.addEventListener('click', function(e) {
var e = e || window.event,
target = e.target || e.srcElement,
text = target.textContent || target.innerText;
if (target.tagName.toLowerCase() == 'label') {
var labels = document.querySelectorAll("label");
[].forEach.call(labels, function(el) {
el.classList.remove("button-press");
});
target.classList.add("button-press");
console.log('text', text);
console.log('target', target);
console.log('tagname', target.tagName.toLowerCase());
}
}, false);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment