开发者

Cannot get click() function to work on jQuery

Thanks in advance for the help:

This function works fine in dropping in the div from the first click function, but 开发者_运维知识库WILL NOT acknowledge the second click function in any capacity whatsoever.

I can even activate the first click function as many times as I want.

What am I missing? I'm ripping my hair out over this.

$('span[rel="confirm"]').click( function() {
    $('.confirmbox').remove();

    targetpath = $(this).attr("targetpath");
    dbid = $(this).attr("dbid");

    $(this).after('<div><span class="closeout">X</span> &nbsp Are you sure you want to <a href="index.php?cmd=deletesample&id=' + dbid + '&filetarget=' + targetpath + '">delete?</a></div>');
    $('.confirmbox').show(200);
});

$('.closeout').click( function() {
    $('.confirmbox').css('background-color', 'green');
});


You're adding the element dynamically, so you need to use $.live() instead:

$('.closeout').live("click", function(){
    $('.confirmbox').css('background-color', 'green');
});


Since you are dealing with dynamic DOM elements, you'll need to change your click() to a live() event instead...

$('.closeout').live('click', function() {
    $('.confirmbox').css('background-color', 'green');
});

Here is a quick demo based on your code link text

For more information about live() check out http://api.jquery.com/live/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜