tags:

views:

65

answers:

2

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');
});
+6  A: 

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

$('.closeout').live("click", function(){
    $('.confirmbox').css('background-color', 'green');
});
Jonathan Sampson
Ha... I should have refreshed )
Elijah Manor
@ElijahManor We've all been there :) Technically your answer is *different* than mine ;) I'll pass a +1 your way!
Jonathan Sampson
Thank you guys so so SO much for the help and the explanation. I figured this was the issue, but had no idea where to even start looking for the solution.
dclowd9901
+3  A: 

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/

Elijah Manor