Latest web development tutorials

HTML DOM isSameNode method

Elements Object Reference Element object

Examples

Check whether two nodes are the same node:

var item1=document.getElementById("myList1");
var item2=document.getElementsByTagName("UL")[0];
item1.isSameNode(item2);

Output:

true

try it"

Definition and Usage

isSameNode () method returns true when a node is the same node in a given node, otherwise it returns false.

Tip: Use isEqualNode () method to check whether two nodes are equal, but not necessarily the same node.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

In addition to Firefox all major browsers support isSameNode () method.

Note: Firefox 10 after the first version is no longer supported isSameNode method, because the method in DOM 4 after having abandoned this method, you can use === to compare two elements.

Note: Internet Explorer 8 has an earlier version of IE does not support this method.


grammar

node.isSameNode(node)

parameter

参数 类型 描述
node Node object 必须。你想要比较的节点。

return value

类型 描述
Boolean 如果两个节点相等返回 true, 否则返回 false。

technical details

DOM version Core Level 3 Node Object


Elements Object Reference Element object