views:

465

answers:

3

I have a webpage using jquery 1.42

The following 2 segments of code live in my page.

$('body').delegate('h2', 'click', function() {
    $(this).after("<p>delegate paragraph!<\/p>");
});

$('body h2').live('click', function() {
    $(this).after("<p>live paragraph!<\/p>");
});

The live method always works, yet the delegate doesn't fire at all.

If I create a trivial page with simple html

<body><h2>blah</h2></body>  

both approaches work. So I'm assuming there is something else going on in my page.

With firebug I am seeing no javascript errors, no html errors. and breakpoints on the delegate method definately do not get hit.

What else might be the cause of delegate not triggering?

EDIT: heres the list of other scripts on the page:

<script type="text/javascript" src="/Scripts/jquery-1.4.2.js"></script>
<script type="text/javascript" src="/Scripts/2010.1.416/telerik.common.min.js">   </script>
<script type="text/javascript" src="/Scripts/2010.1.416/telerik.textbox.min.js"></script>
<script type="text/javascript" src="/Scripts/2010.1.416/telerik.grid.js"></script>
<script type="text/javascript" src="/Scripts/2010.1.416/telerik.grid.filtering.min.js"></script>
<script type="text/javascript" src="/Scripts/2010.1.416/jquery.validate.min.js"></script>
<script type="text/javascript" src="/Scripts/2010.1.416/telerik.grid.editing.min.js"></script>
A: 

well, first at all even if I guess this is just an example:

Using delegate on the document body, doesn't make much sense at all obviously . That would force .delegate() to work the same way .live() already does.

I wrote a jsbin link into the comments, those lines of code work fine there (chrome).

You are not doing anything wrong (technically).

Kind Regards

--Andy

jAndy
+2  A: 

It appears as the toolset I was using, Telerik ASP.NET MVC controls 2010.1.416 had a reference to jquery.validate.min.js

The version of the file they ship is 1.5.5

Updating this version to 1.7 and delegate is again working as expected.

/smack.

Jafin
don't forget to mark this as the correct answer. Good work on finding the fix.
Alastair Pitts
A: 

Thanks for posting that smack, using the same library.