Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get click() function to work on jQuery

Tags:

jquery

click

hide

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');
});
like image 923
dclowd9901 Avatar asked Sep 03 '26 02:09

dclowd9901


1 Answers

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

$('.closeout').live("click", function(){
    $('.confirmbox').css('background-color', 'green');
});
like image 62
Sampson Avatar answered Sep 05 '26 15:09

Sampson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!