开发者

Jquery - intercept links created by ajax request

开发者 https://www.devze.com 2022-12-23 22:49 出处:网络
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() { $(\"a\").click(function() {

I have some jQuery code that intercepts links clicked on a page:

$(document).ready(function()
{   
        $("a").click(function() {
            //do something here
        });
});

My problem is there are certain parts of the page that have not finished loading on document ready. They are populated via ajax calls. The links in these sections are not intercepted by my jQuery function above.

I need the function to be run on document ready initially but then I need the new links to also have the same logic applied to them.

Any help would be very mu开发者_JAVA技巧ch appreciated. This is an area that I am very unfamiliar with. I have written the jQuery stuff but the ajax code is an external component that I have no control over.


Use live():

$("a").live("click", function() { 
        //do something here 
}); 


use live()

$("a").live('click',function() {
            //do something here
        });
0

精彩评论

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