Last active
January 18, 2018 14:34
-
-
Save AlexR1712/91bd9b10182bb16427e2ec8975e5b12b to your computer and use it in GitHub Desktop.
Get element clicked
This file contains hidden or 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
document.addEventListener('click', function(e) { | |
e = e || window.event; | |
var target = e.target || e.srcElement, | |
text = target.textContent || text.innerText; | |
}, false); | |
// Version Two | |
if (document.addEventListener){ | |
document.addEventListener("click", function(event){ | |
var targetElement = event.target || event.srcElement; | |
console.log(targetElement); | |
}); | |
} else if (document.attachEvent) { | |
document.attachEvent("onclick", function(){ | |
var targetElement = event.target || event.srcElement; | |
console.log(targetElement); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment