Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get element clicked
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
You can’t perform that action at this time.