Skip to main content

Bug Tracker

Side navigation

#7648 closed bug (invalid)

Opened November 28, 2010 04:44PM UTC

Closed November 28, 2010 07:31PM UTC

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

Reported by: carlo.cabanilla@gmail.com 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>

Attachments (0)
Change History (2)

Changed November 28, 2010 05:33PM UTC by carlo.cabanilla@gmail.com comment:1

Oops, just noticed the message about using jsFiddle:

http://jsfiddle.net/5nPus/

Changed November 28, 2010 07:31PM UTC by dmethvin comment:2

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.