1

I need to make the event of the window to be triggered first, on clicking on the #myDiv, is there a way to do it?

(function ($, w, d) {
    $(d).ready(function () {
      $(w).click(function() {
         alert('window has been clicked'); 
      });

      $('#myDiv').click(function () {
         alert('myDiv has been clicked'); 
      });
   });
})(jQuery, window, document);

check this out http://jsfiddle.net/au1hpj5L/

Husamuddin
  • 405
  • 1
  • 7
  • 19

1 Answers1

0

You could wrap the anonymous #myDiv function in a setTimout call set for 0 seconds, which would delay its execution in the event loop.

http://jsfiddle.net/2y5h8fgz/

(function ($, w, d) {
    $(d).ready(function () {
        $(w).click(function() {
           alert('window has been clicked'); 
        });
        $('#myDiv').click(function(){
            setTimeout(function () {
           alert('myDiv has been clicked'); 
        }, 0);
        });
    });
})(jQuery, window, document);
Aweary
  • 2,302
  • 17
  • 26