0

I'm trying to get my javascript to work on pages I load through the .load command.

$("#loadingDockShotPg").load("include/shot_comments.php");

I'm doing this to load a subsection of a page, but the problem is, the div within the newly loaded page isn't being affected by my jQuery file that I have in the parent file. What is a better way to load content so that the newly injected can be affected by my javascript?

4

1 回答 1

3

I'm assuming that you're issue is with event listeners.

If, for example you're using:

$('.something').click(function(){ 
   // DO SOMETHING 
});

Try changing it out for:

$(document).on('click','.something',function(){ 
   // DO SOMETHING 
});

This way the jQuery will listen for any clicks on the document and apply the action to events that match clicking on the .something object.

于 2012-11-02T20:10:50.083 回答