Reputation: 35
I want to use element in the event listener function without declaring it elsewhere in Javascript.
element.addEventListener("click",function(){
//want to access element here
})
Upvotes: 1
Views: 510
Reputation: 28424
You can do this in two ways:
element.addEventListener("click",function(e){
console.log(this);
console.log(e.currentTarget);
})
<button id="element">Click</button>
Upvotes: 2