したいこと:
ウェブページにある要素の前にリンクを付けたい。
最初のページは簡単ですが、でもその以降のデータ取得はAjaxでとっています(Ajax.onSuccess($('a').html(data))の形で)ので、新たに撮ったデータにリンクが付けられません。
解決策はDOM要素のDOMSubtreeModified
イベントを利用しました。
function addLinks(){
$("div[class='question-box']").each(function(){
// do something ...
});
}
function DOMModificationHandler(){
$(this).unbind('DOMSubtreeModified');
setTimeout(function(){
addLinks();
$('.question-list').bind('DOMSubtreeModified',DOMModificationHandler);
},1500);
}
// add links for first page(loaded not by Ajax).
addLinks();
//after document-load(for ajax response)
$('.question-list').bind('DOMSubtreeModified',DOMModificationHandler);