JQuery delegate conflicts with another delegate in IE

It seems that in IE, some delegates might somehow cause the other delegate to fail.

This is one of the possible cases:

<html>
 <head>
  <script src='jquery-1.4.2.min.js'></script>
  <script>
   $(function() {
    $('#main')
    .delegate('div', 'click', function() {
     alert('on div!');
    })
    .delegate('[name=first]', 'change', function() {
     alert('first!');
    })
    .delegate('[name=second]', 'change', function() {
     alert('second!');
    })
    ;
   });
  </script>
 </head>
 <body>
  <div id="main">
   <input name="first" />
   <input name="second" type="checkbox" />
   <div>Test</div>
  </div>
 </body>
</html>

In this particular case, the handler for the flag will not fire.

As usual, the problem does not appear in other browsers.

Changing call orders may solve the problem, but runs the risk of causing another. Please note that the delegate is working on mutually exclusive elements, so the order should be irrelevant.

What causes this?

+3
source share
3 answers

It seems that the problem was resolved in the latest version of jQuery or Internet-Explorer (starting from this entry, 1.5 and 9, respectively).

0

; IE8. , , , . , checkbox, , .

, , , .

, . , , , id, .

0

I also came across this. For some reason, changing the order in which events were recorded fixed this for me. I would like the explanation.

0
source

Source: https://habr.com/ru/post/1763015/


All Articles