HTML DOM isSameNode()Method

元素对象参考手册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 result:

true

Try it yourself »

Definition and Usage

The isSameNode() method returns true if a node is the same node as the given node, otherwise it returns false.

Tip:Use theisEqualNode() methodto check whether two nodes are equal, but not necessarily the same node.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All mainstream browsers support the isSameNode() method except Firefox.

Note:Firefox no longer supports the isSameNode() method after version 10, because the method was deprecated after DOM 4. You can use === to compare two elements.

Note:Internet Explorer 8 and earlier IE versions do not support this method.


Syntax

node.isSameNode(node)

Parameters

Parameter Type Description
node Node object Required. The node you want to compare.

Return Value

Type Description
Boolean Returns true if the two nodes are equal, otherwise returns false.

Technical Details

DOM Version Core Level 3 Node Object


元素对象参考手册Element Object

Other Extensions