开发者

Using jQuery load() on dynamic content

开发者 https://www.devze.com 2023-04-03 06:12 出处:网络
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.

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().


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消