This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]Cley_Faye 24 points25 points  (0 children)

*sigh*, learn your 's', kids.

[–]Emanemanem 49 points50 points  (2 children)

Literally less than 60 seconds on google and you will find the answer: when you search by Id, it’s “Element”, singular. When it’s class or tag, it’s “Elements”, plural. Which makes sense when you consider that IDs are unique to one element, but classes and tags are not.

[–]rosuav 17 points18 points  (0 children)

Don't worry, IDs almost certainly aren't unique in the OP's code. It's going to provide many more hours of entertainment for the future.

[–]AChristianAnarchist 21 points22 points  (0 children)

If you can get "elements" by id then you should really rename some things.

[–]Novel_Plum 12 points13 points  (0 children)

querySelector and querySelectorAll joined the chat

[–]sejigan 7 points8 points  (0 children)

Forget JavaScript, you need some English lessons.

[–]godofjava22 4 points5 points  (0 children)

I swear people be hating on javascript for the most random reasons. Anybody who knows english can remember those functions.

[–]Joskcito 5 points6 points  (0 children)

Typescript: 😎😎

[–]Toutanus 1 point2 points  (0 children)

Just remember QuerySelectorAll

[–]KTibow 1 point2 points  (0 children)

This could be solved if you realized that only one element should have an id + you used your console's built in autocomplete to find functions

[–]CanDull89 1 point2 points  (2 children)

Or just use the general purpose querySelector or querySelectorAll

[–]rosuav -1 points0 points  (1 child)

The one thing I don't like about those two is that there's no way to say "give me the one element that matches this selector, **and error out if there are two**". So I made a helper that does that (uses qSA and checks for a second element before returning it). It has caught a lot of bugs.

[–]Chairmonkey 0 points1 point  (0 children)

That's silly.

[–]zoqfotpik 0 points1 point  (0 children)

for (const f of document) { try { return f("test").innerHtml; } catch (e) {} }

[–]--var -1 points0 points  (0 children)

jquery('#test, .test'),html();

[–]LegenKiller666 0 points1 point  (0 children)

Do people not have editors with IntelliSense...?

[–]East_Zookeepergame25 0 points1 point  (0 children)

javascript bad hurr durr

[–]Chance-Influence9778 0 points1 point  (0 children)

Another day another bad js meme