我想知道什么是最简洁的方式来找到周围Element
s给定MutationRecord
?从MutationRecord获取nextElementSibling(previousElementSibling)的最简洁方法是什么?
MutationRecord
具有.nextSibling
,.previousSibling
属性,但可能包含文本节点,我需要获得常规元素节点。
工作例子是在这里:http://jsfiddle.net/tomalec/ceku2/
我尝试使用
mutation.addedNodes[0].previousElementSibling;
mutation.addedNodes[mutation.addedNodes.length - 1].nextElementSibling);
http://jsfiddle.net/tomalec/Q2HFY/2/
但是它看起来有点冒险,它不适合去除那些在所有的工作。
mutation.removedNodes[0].previousElementSibling; //null
mutation.removedNodes[mutation.removedNodes.length - 1].nextElementSibling); //null
http://jsfiddle.net/tomalec/Q2HFY/3/