2

I have an element:

<div id="someElement"></div>

I have a global variable:

var someElement;

On Chrome, Edge, IE, FireFox, Opera... if I console.log(someElement), it is undefined. I initialize someElement to a widget later, so I utilize the fact that it is undefined for certain if-statement checks to only execute certain code after the widget is initialized.

However, in Safari.... someElement is evaluating to

<div id="someElement"></div>

My understanding was any global variables overshadow any 'globals' made with element ids, so this should not be happening...

I guess I am not fully understanding the Safari behavior when every other browser is behaving as expected. What is going on here?

Tyler Dahle
  • 817
  • 1
  • 8
  • 37
  • Looks like the millionth bug in Safari ... – Teemu Feb 23 '18 at 16:35
  • As far as I know this is somewhat new? I didn't have any issue like this popping up a while ago (not horribly long ago). – Tyler Dahle Feb 23 '18 at 16:37
  • 1
    https://stackoverflow.com/questions/3434278/do-dom-tree-elements-with-ids-become-global-variables – Endless Feb 23 '18 at 16:39
  • Yes, I saw that. That is not an entirely related question. The OP there is asking about actually USING ids as variable names. And literally the third paragraph of the accepted answer explains why what I am posting about is odd behavior, and it fails to answer why Safari is behaving this way. – Tyler Dahle Feb 23 '18 at 16:44

0 Answers0