Емил Цоков
Емил Цоков

Reputation: 692

Comparing two DOM elements in javascript (the proper way)?

I have the following js code:

changeVideo(element) {
  const currentVideo = document.querySelector('.current-video');
  const nextVideo = document.querySelector(`${element}`);
  if (currentVideo === nextVideo) {
    return;
  }
  // more code here
}

Is this the correct/proper way to compare DOM Elements? (currentVideo === nextVideo)

The expectation is for this to work in all modern browsers.

Upvotes: 1

Views: 2060

Answers (1)

shyke
shyke

Reputation: 194

I guess after almost 2 years the problem has been solved... but for future searches, you can use Node.isEqualNode() for more information go to MDN on the subject

Upvotes: 2

Related Questions