はい、ミューテーションオブザーバーコールバックに返されるデータにjQueryセレクターを使用できます。
このjsFiddleを参照してください。
あなたがそのようなHTMLを持っていたとしましょう:
<span class="myclass">
<span class="myclass2">My <span class="boldly">vastly</span> improved</span>
text.
</span>
そして、次のようにオブザーバーを設定します。
var targetNodes = $(".myclass");
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var myObserver = new MutationObserver (mutationHandler);
var obsConfig = { childList: true, characterData: true, attributes: true, subtree: true };
//--- Add a target node to the observer. Can only add one node at a time.
targetNodes.each ( function () {
myObserver.observe (this, obsConfig);
} );
function mutationHandler (mutationRecords) {
console.info ("mutationHandler:");
mutationRecords.forEach ( function (mutation) {
console.log (mutation.type);
if (typeof mutation.removedNodes == "object") {
var jq = $(mutation.removedNodes);
console.log (jq);
console.log (jq.is("span.myclass2"));
console.log (jq.find("span") );
}
} );
}
でjQueryを実行できることに注意してくださいmutation.removedNodes
。
その後$(".myclass").html ("[censored!]");
、コンソールから実行すると、ChromeとFirefoxからこれを取得します。
mutationHandler:
childList
jQuery(<TextNode textContent="\n ">, span.myclass2, <TextNode textContent="\n text.\n ">)
true
jQuery(span.boldly)
これは、返されたノードセットで通常のjQuery選択メソッドを使用できることを示しています。