Comparing a DOM Node to a DOM Element

I am having trouble resolving this issue. I know that everything in the DOM is node and that the DOM element is also node. However, my problem is this: I have a DOM node and a DOM element, and I need to compare them to see if they belong to the same element. Is it possible? I think that there is something fundamentally wrong with my question, but I can’t understand what it is. Thank you for your help.

+3
javascript dom
Jun 23 '12 at 19:50
source share
1 answer

Just compare === . Since both objects are objects, the comparison will be based on identification.

 if (my_node === my_element) { // they're the same thing } 
+3
Jun 23 2018-12-12T00:
source share



All Articles