开发者

jQuery Ajax don't remember generated code?

I just started using Ajax with jQuery and PHP. I have a working code (below) which inserts some HTML code to a HTML container (div called nav sub).

Next time I try to run a similar code to the one below on my generated HTML, jQue开发者_开发问答ry don't seem to find it. I guess it don't update it self about it when it's added.

$(".nav.top a").click(function(){
    var a_class = $(this).parent().attr("class");

    $(".nav.sub").html("loading...");
    $(".nav.sub").load("<?php echo get_bloginfo('url'); ?>/?addmod_ajax=1",{button: a_class});
    return false;
});

Let's say the generated code looks like this:

<div class="nav sub">
    <a href="#">My new generated button, forgotten by jQuery?</a>
</div>

And the new container looks like this:

<div class="settings"><?php # AJAX ?></div>

Is it some way to use jQuery and Ajax on HTML code generated with jQuery?


I figured it out. The solution is to use "live".

$('.nav.top a').live( 'click', function() {
    var a_class = $(this).parent().attr("class");

    $(".nav.sub").html("loading...");
    $(".nav.sub").load("<?php echo get_bloginfo('url'); ?>/?addmod_ajax=1",{button: a_class});
    return false;
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜