イベントバインディングだけが欠落している場合は、を使用してイベントの委任を調べてください.on
。次のようになります。
$('#loadContainer').on('click', '#loadedElement', function(){
//will work even if called before elements are loaded
});
ただし、イベントバインディングよりもはるかに多い場合は、関連するコードを関数でラップし、組み込みのコールバックを使用してajaxロード後に呼び出す必要があります。このようなもの:
function relevantStuff(){
//things needed by loaded content
}
relevantStuff(); // run right away incase you need parts or all of this before the content is loaded as well
$.post('yourUrl.php', function(result){
$('#loadContainer').append(result); //inject html into page
relevantStuff(); //do the stuff after load
});
また、ajaxを使用して「htmlを取得」してページに「ロード」する場合は、.get
またはを使用することを検討してください.load
。