Are JavaScript equality operators for DOM elements a cross browser?

Will == and === work correctly in all browsers for DOM elements? If the code gets a link to the raw DOM element in two different ways, will they be equal == and === in all browsers?

+6
source share
1 answer

Will == and === work correctly in all browsers for DOM elements?

Yes, these equality operators will work as defined by the ECMAScript standard.

One word of caution, == often does things that developers do not expect, such as casting a string to a comparison against a string value. This would make the following statement true, although this may not be the desired result:

 document.createElement('div') == '[object HTMLDivElement]' 

In most cases, you need to use the === operator.

+5
source

All Articles