Bug Tracker

Opened 10 years ago

Closed 10 years ago

#7648 closed bug (invalid)

data events don't trigger .live() event handlers

Reported by: carlo.cabanilla@… Owned by:
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description

It seems like the data events (setData, changeData, getData) aren't triggering event handlers set with .live(). A minimal test case:

<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script>
      $(document).ready(function() {
        var logger = function(evt, key, val) {
          $('#log').append('<p>' + evt.type + ':' + key + ':' + val + '</p>')
        };
        $('.container')
          .live('setData', logger)
          .live('getData', logger)
          .live('changeData', logger);
        
        $('#c1').data('a', 'foo');
        $('#c1').data('a', 'bar');
        $('#c1').data('a');
        $('body').append('<div class="container" id="c2"></div>');
        $('#c2').data('b', 1);
        $('#c2').data('b', 2);
        $('#c2').data('b');

        var expected = [
          "<p>setData:a:foo</p>",
          "<p>changeData:a:foo</p>",
          "<p>setData:a:bar</p>",
          "<p>changeData:a:bar</p>",
          "<p>getData:a:undefined</p>",
          "<p>setData:b:1</p>",
          "<p>changeData:b:2</p>",
          "<p>setData:b:2</p>",
          "<p>changeData:b:2</p>",
          "<p>getData:b:undefined</p>"
        ].join("");
      
        var actual = $('#log').html();
      
        if (actual == expected) {
          $('#message').append('Test passed');
        } else {
          $('#message').append('Test failed. Expected: ' + expected + ' Actual: ' + actual);
        }
      

      })
      
    </script>
  </head>
  <body>
    <div id="message"></div>
    <div class="container" id="c1"></div>
    <div id="log"></div>
  </body>
</html>

Change History (2)

comment:1 Changed 10 years ago by carlo.cabanilla@…

Oops, just noticed the message about using jsFiddle:

http://jsfiddle.net/5nPus/

comment:2 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

Note that in jQuery 1.4.3 these events no longer bubble (allowing them to bubble proved to be too costly in most applications). -- http://blog.jquery.com/2010/10/16/jquery-143-released/

Bubbling is required for .live or .delegate to work.

At the moment, the data events are lightly documented so it's not advisable to write code that depends on them or their current behavior.

Note: See TracTickets for help on using tickets.