views:

125

answers:

1

Is there a restriction on the complexity of selectors that can be used with delegate in jQuery 1.4.2?

This works for me:

   $('.activeTabsList').delegate('.activeTabsListItem', 'click', 
function() { 
   alert('here'); 
});

This does not work:

    $('.activeTabsList').delegate('.activeTabsListItem:not(.selected)', 'click', 
function() { 
   alert('here'); 
});

As you can probably assume, there is only 1 item at a time that has the selected class. When I click the other tabs, my delegate handler is still not fired.

+3  A: 

The code you have works, you can see a demo here. Make sure that your selector matches like you think it does, this is most likely the issue....delegate() itself handles this case.

Usually this happens as a result of something like this, over-assigning the selected class:

$(".activeTabsListItem").click(function() {
  $(".activeTabsListItem").addClass("selected"); //should have been $(this)
});
Nick Craver
Thanks - just making sure I wasn't trying to do something unsupported before I really try to look into it deeper. None of the demos cover anything beyond simple selectors. I've never seen jsFiddle, but that's a pretty sweet tool
Keith Rousseau
+1 for the answer....if I could give another for the link to jsFiddle, I would...nice tool!
Bradley Mountford
My problem ended up being because I am using this with the ui tabs. That fires first so my tab is always selected by the time my event fires.
Keith Rousseau