2

I'm trying to load content into a DIV with jQuery load() but it is not working if the link that calls the function is generated after page load.

var ajax_load = "<img class='loading' src='ajax-loader.gif' alt='loading...' />";
$(".slide_more").click(function() {
    $("#ajaxcontent").html(ajax_load).load('p=4324.php #singlePost');
});

and the generated link:

<a href="#" class="slide_more" id="load_basic">LOAD</a>

I've tried using live() and delegate() with no luck:

$(".slide_more").live('click', function() {
    $("#ajaxcontent").html(ajax_load).load('p=4324.php #singlePost');
});

The strange thing is that the .slide_more class also calls a simple jQuery toggle which is working with live().

12
  • Have you use firebug to see if the ajax call works? I suspect your url is being misinterpreted. Commented Sep 8, 2011 at 8:59
  • the generated link is generated after page load. this code must be executed after link is generated Commented Sep 8, 2011 at 9:02
  • Yes, under the NET/XHR nothing appears except the generated content that contains the link. Commented Sep 8, 2011 at 9:02
  • Yes it is inside (document).ready() Commented Sep 8, 2011 at 9:03
  • 1
    @elbatron: jsfiddle.net/mattlunn/2ytnW. You're barking up the wrong tree. If the image path/ AJAX url existed in my Fiddle, it'd work fine. Commented Sep 8, 2011 at 9:26

1 Answer 1

1

The jQery snippet with the live() handler added to click() event is working fine. I just had to make sure that the code is at the top of the page before any other code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.