我想知道在给定的情况下找到周围Element
s的最干净的方法是什么MutationRecord
?
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