2
$j(".context-menu").livequery(function(){
    alert('found');
});

This was working until a couple of days ago. It just suddenly stopped. On addition of new elements with class 'context-menu' nothing happens.

Although in firebug if I run the above statement, its found and an alert is thrown.

Any idea what the problem could be ?

HTML:

<html>
<head>
    <script type='text/javascript' src='/scripts/prototype.js'></script>
    <script type='text/javascript' src='/scripts/jquery-1.4.2.js'></script>
    <script type='text/javascript'>
    var $j = jQuery.noConflict();
    </script>
    <script type='text/javascript' src='/scripts/jquery.livequery.js'></script>
</head>
<body>
    <div class='fun'>fun</div>
</body>
Dean Burge
  • 3,440
  • 25
  • 22
Prakash Raman
  • 13,319
  • 27
  • 82
  • 132

3 Answers3

0

Did you update any of your other Javascript code? It seems like you have a syntax error or something in the rest of your Javascript which would mean that everything (including this part) fails.

Run your site with the Firebug error console active and make sure it catches Javascript errors and warnings by checking your settings (the arrow in the console tab).

  • Could you tell me what the error is. Since the page loads fine, without breaking. Firebug doesn't say anything either – Prakash Raman Jan 29 '11 at 10:23
  • No, not without seeing more of your code or being able to debug your site myself. Can you send me either a link or your entire Javascript-code? –  Jan 29 '11 at 10:25
  • To make things easier I don't have any js files that are run (other than jquery). After the page loads I run the mentioned js in firebug. Then I try document.body.appendChild(el) and it doesn't seem like livequery is being called. – Prakash Raman Jan 29 '11 at 10:27
0

Did you recently upgrade to jQuery 1.4.2? I don't think the livequery plugin is fully compatible with jQuery 1.4+

mVChr
  • 49,587
  • 11
  • 107
  • 104
0

I created this simple snippet to test if livequery works with current jQuery and it does with no problem (here's the jsfidde http://jsfiddle.net/x3tds/1/):

<a href="javascript:void(0)" onclick="adddiv('')">Click me</a>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

<script src="http://brandonaaron.net/javascripts/plugins/livequery.js"></script>


<script>

jQuery("div").livequery(function() { alert("div added") })

function adddiv()
{
    jQuery("a").append("<div>Hello</div>")
}
</script>
Andrey
  • 20,487
  • 26
  • 108
  • 176
  • Yep. But it does not solve my problem. Since I need a callback on whenever a new element (matching my selector) has been added to the dom. – Prakash Raman Jan 31 '11 at 07:30
  • Thanks :) It worked for me. Only difference was that I was using jquery-1.4.2. May that was it :) Thanks. – Prakash Raman Feb 03 '11 at 17:34