How to access elements of an external page if that page is loaded into a div using load function?
I am loading an external page into a div using jQuery and making that div to popup. Somehow I managed to do all these. The problem here is, I have a close mark in the page that was loaded externally but开发者_如何学编程 I wanted to access it from the current page. It is not working if I give it in the normal way like
$('#close').click(function (){
// code
});
Use .live() instead of .click() or put your present code on page load
$('#close').live("click", function (){
// code here
});
I had the same situation my situation was that I used to use
$('#close').live("click", function (){ // code here});
But as I was developing a single page web application, it caused a big mess. What I actually did later was to put up all my commonly used jQuery in a separate .js file, and include it in every page load and now it works just fine.
And I changed the live click to
$('#close').click(function (){ // code });
same as you have done.
精彩评论