I have this simple scenario where I am first binding javascript event listeners like so:
(function () {
/*Loading widget initialization code on window load*/
if (window.addEventListener) {// W3C standard
window.addEventListener('load', initWidget, false);
} else if (window.attachEvent) {// Microsoft
window.attachEvent('onload', initWidget);
}
})();
Please don't mind the initWidget
as it is defined and works I just didn't put the code here since it was not needed.
So these events work fine, but when I add some jquery event handlers in there, the jquery events don't work. I add the jQuery events in $.ready()
like so :
$().ready(function() {
$("#header").mouseover(function() {
$("#header").css("background-color", "red");
}).mouseout(function() {
$("#header").css("background-color", "transparent");
});
})
The jQuery mouseover
and mouseout
don't work unless I remove the window.addEventListener
code block. Somehow js events are causing conflicts with jQuery and there is nothing in console.
I have also put up a fiddle here : https://jsfiddle.net/kzmvaysq/ replicating the exact problem. I need a way so that event listeners don't conflict with jQuery.
UPDATE
I traced to the main problem area and that seems to be trying to change the innerHTML of body
tag in initWidget
. If you see the fiddle now : https://jsfiddle.net/kzmvaysq/4/ it might help you better understand the problem.