jquery - Unable to get property 'hasClass' of undefined or null reference -


i using angularjs framework , using 'hasclass' inside jquery in order have dropdown on mouse over. working fine in chrome , ff in ie, gives error "unable property hasclass of undefined or null reference" when click on button , navigate page. error not show every time appears , in ie only. similarly, instead of 'hasclass', throws 'height' undefined or null reference. here code:

(function ($, window, delay) {          var thetimer = 0;         var theelement = null;         var thelastposition = { x: 0, y: 0 };         $('[data-toggle]')           .closest('li')           .on('mouseenter', function (inevent) {               if (theelement) theelement.removeclass('open');               window.cleartimeout(thetimer);               theelement = $(this);                thetimer = window.settimeout(function () {                   theelement.addclass('open');               }, delay);           })           .on('mousemove', function (inevent) {               if (math.abs(thelastposition.x - inevent.screenx) > 4 ||                  math.abs(thelastposition.y - inevent.screeny) > 4) {                   thelastposition.x = inevent.screenx;                   thelastposition.y = inevent.screeny;                   return;               }                if (theelement.hasclass('open')) return;               window.cleartimeout(thetimer);               thetimer = window.settimeout(function () {                   theelement.addclass('open');               }, delay);           })           .on('mouseleave', function (inevent) {               window.cleartimeout(thetimer);               theelement = $(this);               thetimer = window.settimeout(function () {                   theelement.removeclass('open');               }, delay);           });     })(jquery, window, 50); // 50 delay in milliseconds 

any suggestions? thanks.

problably, problem mousemove event may fire earlier mouseenter in cases.

then, better check if theelement still null in mousemove event listener:

.on('mousemove', function (inevent) {     /* ... */     if (!theelement || theelement.hasclass('open')) { return; }     window.cleartimeout(thetimer);     thetimer = window.settimeout(function () {         theelement.addclass('open');     }, delay); }) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -