javascript - How to pass Event (e) and variables with event listeners? -
i have event listener this:
div.addeventlistener('mouseover',function(){bubble_info.call(data);},false);  function bubble_info(e,info){   //get e.pagex etc   //do stuff info } this problem in bubble_info variable e holds info of data , info undefined
how make sure can e , info correctly?
event object has many useful properties , methods.
div.addeventlistener('mouseover',function(event){     bubble_info(event, info);      // can pass additional params can used in handler  },false);  function bubble_info(event, info){   // can access type of event event object's properties   console.log(event.type);   console.log(info); // additional parameter. }; addeventlistener documentation
use call if need pass reference of this (current) object. it's syntax ...
functionname.call(thisarg, arguments-list, ...); 
Comments
Post a Comment