Murtaza Mandvi
Murtaza Mandvi

Reputation: 10988

Jquery - dynamic DIV onclick binding

I have a main page from where I am making a call to "load" and intermediate page's HTML and on the completion of the load I am massaging the returned HTML to add a few DIVs etc, when I try to bind an onclick event for the dynamic Divs (added by me after the HTML returned from the intermediate page) it does not seem to work at all !:

LOAD :

$j(".loader").load(myURLtoIntermediatePage, '', function() {
     var HTML= '<div id="abcd">test</div>';
     ...

     $j(".pageDIV").append(HTML);    
}

DOCUMENT READY Function

$j(document).ready(function() {

 $j('#abcd').onclick(function() {
            alert($j(this));
        });

});

Upvotes: 3

Views: 5562

Answers (1)

Joe Chung
Joe Chung

Reputation: 12123

This requires jQuery 1.3:

$j("#abcd").live("click", function() {
    alert($j(this));
});

Upvotes: 7

Related Questions