You are correct about the bind.  Here's how I'd approach it.....

$(document).ready(function(){
        // Function to initiate our bind to the click event on the 
        init();
        
        // Bind the button which will always be bound
        $('#button').bind(      'click', 
                                function(){
                                        $.ajax({
                                                ....,
                                                success: function(){
                                                        // On a successful
respond put the                                                           //
into Our div (something)
$('#something').html(ajaxreponsevar);
                                                        // Reinitiate the
bind event images
                                                        init();

                                                }       
                                                });
                                        });     
});

function init(){
        // PUT THE unbind in there so that any other images that were
previous 
        // bound and not reload are not double bound
        $('divstuff img').unbind('click').bind('click',function(){
                                                                        //
DO SOMETHING
                                                                        });
}

That way you initiate the bind on the initial load, and then reinitiate it
when you click on the button (with id="button")

I am not an expert by any means, and that is just how I'd go about it. There
are most likely better solutions, but I hope that helps. 

- David

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kim Johnson
Sent: Sunday, March 18, 2007 11:24 AM
To: jQuery Discussion.
Subject: [jQuery] Event not firing inside unhidden div

I have a div which is invisible by default, and
becomes visible via slidetoggle when a button is
clicked. Inside the div is dynamic content via ajax --
i take the responseText of an ajax call, and then
append it to an empty div (inside the slidetoggled
div) via .html(ajaxreponsevar). I do it this way
because I use the same div for multiple bits of
dynamic content, a different bit depending on which
button is clicked.

This approach works fine for getting/showing the
dynamic content. However, now I'm trying to add a
click event to an image inside that dynamically
generated content, and it's not working. I am thinking
this is maybe because my jquery bind events and such
are loaded once on page load (in a php file), and and
thus can't bind to something that doesn't exist yet?

I also tried ("divstuff img").bind(click, function(){
...etc (which I think is the same thing as just saying
divstuff img.click()) but that didn't work either. 

I'm guessing there's some sort of trick to binding
events to dynamic content? 

thanks!
-kim


 
____________________________________________________________________________
________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to