This has nothing to do with jQuery or hasClass()
. It is entirely down to your use of console.log()
.
It is important to know that IE does not define the console
object until the F12 dev tools window has been opened.
This means that before you open it, the console
calls will be throwing javascript "object undefined" errors. This will make it appear that the code around it isn't working, but it's really just the fact that the console object is missing.
You may have similar effects in other older browsers, but most current browser versions do not do this -- they define the console
object immediately, regardless of whether the dev tools is open or not. IE is the only exception.
You can get around this by either (a) not using console
unless you are actually debugging and have the dev tools open, or (b) adding an if(console)
check to all your console
calls. This will prevent the error.
Further information here: Why does JavaScript only work after opening developer tools in IE once?