isEqualNode method
9 | ||||
Returns whether the current node is equal to the specified one.
When we speak about nodes in JavaScript, it exactly means node object references.
Two node references are the same if they reference to the same object.
You can get whether two nodes are the same with the isSameNode method.
When two node references are the same then they are also equal, but different node references can also be equal.
Two nodes are equal, when their names are the same, their attributes have the same name and value (the order of attributes may be different), and their child nodes are equal an they are in the same order.
That is an simplified definition of two nodes equality, if you need the exact definition of it, please see the isEqualNode (W3C) page.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. Reference to the node to compare. |
Return value:
Boolean. One of the following values:
The specified node and the current node are not equal. | |
The specified node and the current node are equal. |
Example HTML code 1:
This example illustrates the use of the isEqualNode method:
|
||||
<head> <script type="text/javascript"> var lastButton = null; function Test (button) { if (lastButton) { if (button.isSameNode) { if (button.isSameNode (lastButton)) { alert ("Last time you clicked on the same button."); } else { alert ("You clicked on another button before."); } } else { alert ("Your browser does not support the isSameNode method."); } if (button.isEqualNode) { if (button.isEqualNode (lastButton)) { alert ("The two last buttons you last time clicked on is equal."); } else { alert ("The two last buttons you last time clicked on is not equal."); } } else { alert ("Your browser does not support the isEqualNode method."); } } lastButton = button; } </script> </head> <body> Click on the buttons! <button onclick="Test (this);">button1</button> <button onclick="Test (this);">button1</button> <button onclick="Test (this);">button2</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
attribute, CommentNode, doctype, document, DocumentFragment, TextNode, XMLDocument
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
Related pages:
External links:
User Contributed Comments