Jquery upgrade - 1.8 to 2.1.4, $(window) click vs $(document) click

403
November 26, 2016, at 8:04 PM

I recently updated my project with latest jquery version.

For jquery 1.8, following statement worked:

$(window).on('click', 'button[data-mynav]', function() {
 console.log('hit');
}
);

But it stopped working with jquery 2.1.4, but if i use $(document) instead of $(window) it works, that is:

$(document).on('click', 'button[data-mynav]', function() {
 console.log('hit');
}
);

Can anyone please explain, why this is happening?

Answer 1

It stop working already on 1.8.1

<button a>works</button> 
<button b>fails</button> 
 
<!-- working --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> 
<script> 
 
  $(window).on('click', 'button[a]', function() { 
    this.innerHTML = 'hit'; 
  }); 
   
  jQuery.noConflict(true); 
   
</script> 
 
<!-- not working --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 
<script> 
 
  $(window).on('click', 'button[b]', function() { 
    this.innerHTML = 'hit'; 
  }); 
   
</script>

This is there changelog between 1.8.0 and 1.8.1

My guess is on bug #12383 git: afd717d

I don't know exactly why it stop working as they didn't mention any breaking changes

Rent Charter Buses Company
READ ALSO
Select drop down and autocomplete uniqness

Select drop down and autocomplete uniqness

I have a div that contains a drop down and an auto complete inputI also have a link to add another field with the same drop down and auto complete combination

245
Is it possible to pause a while loop until an animation finishes?

Is it possible to pause a while loop until an animation finishes?

I'm trying to run a while loop that contains an animationWhat I'd like to happen is for the while loop to pause, let the animation finish, then resume

278
Multiple selector not working with jQuery and find() method

Multiple selector not working with jQuery and find() method

Whenever I use the multiple selector operator inside the find method it disregards the comma and reads all classes as oneI'm trying to disregard { and } in p tag elements

437