What do you mean you can just bareback calling an HTML element in javascript without declaring a variable for it or chaining off getElementById()?!

How long has this been the case and I didn't know?? I mean, it's a bad idea in general and I'm not going to do it, but what the hell?

Literally nothing talks about this unless you already know it's true and go looking for why. I guess there's a good reason for that: it's a terrible idea to rely on it.

@trysdyn Your guess is exactly correct - this used to be a more common practice in the bad old IE6 days, if I remember correctly, especially with form elements, but at some point people realized that this was generating bugs like nobody's business and so it got functionally deprecated by the broader webdev community

@joepie91 Yeah I found out because wrote a bug in something where I getElementById()ed a bunch of things into placeholders then did a bunch of operations on them, and missed one and the code worked anyway until I started pointing linters at it and they started screaming about this completely undefined variable that happened to be the same as the element's ID.

That was a very confusing moment or two.

So it's still causing bugs ;)

@trysdyn I *think* this behaviour is one of the things that's turned off in strict mode? But I'm not 100% sure

· · Web · 1 · 0 · 0

@joepie91 Yeah. Part of this massive refactor/cleanup pass I'm doing is to get to the point where I just start using that. This codebase started as my fuck-around/find-out project and now I'm in a place where I think I can handle the finding out.

Sign in to participate in the conversation
Pixietown

Small server part of the pixie.town infrastructure. Registration is closed.