4 ms·
> element.nextSibling is very clear. It's the next sibling of the element. It's idiomatic javascript, and it follows a good naming convention, which is a skill
by Carpetsmoker 7y ago
> element.nextSibling is very clear. It's the next sibling of the element. It's idiomatic javascript, and it follows a good naming convention, which is a skill that is language agnostic.
The only catch here is that it will give you the wrong answer, and that you should (almost) never use it since it includes whitespace nodes, which you practically never want. This is why nextElementSibling exists (get the next sibling that is an element).
As for the naming: this is an old old discussion we will never agree on, but I think that in the context of a DOM traversal library "next" is pretty clear.
> The author is also conflating their time learning as a pro for jQuery. Had they learned vanilla javascript first, their point about not knowing which nextSibling to use would be moot.
Your assumptions about my knowledge couldn't be more wrong. I spent years writing plain JavaScript. I even wrote a jQuery alternative back in the day as I didn't like various aspects of it (I think I was the only user), before giving in and "just using jQuery". I still don't like those same aspects, but it's not bad enough to use something else.
I have also, recently, tried very hard to use plain JS, and this post is the result.
> if you are a new developer do yourself a favor and learn the foundation it's built on first.
This is just a variant of the old "kids these days, they just learn Python instead of REAL development with C, they don't even know the difference between the stack and heap!!" Okay, shrug. In the meanwhile, those "kids" are solving real problems, so well... Programming isn't some kind of intellectual exercise, it's a tool to solve problems.
- ehnto 7y ago> The only catch here is that it will give you the wrong answer, and that you should (almost) never use it since it includes whitespace nodes But that's perfect, because it does what it says. If I wanted to get the next element only I would used the correctly named nextElementSibling. How do you get the next text node sibling in jQuery? > Your assumptions about my knowledge couldn't be more wrong. My apologies. I was reading between the lines and I guess I got it wrong. > This is just a variant of the old "kids these days... Not at all, it's advice for the future of the web which will be more plain javascript based but within frameworks like React and Vue. They're grabbing more and more of the job market share. I am being pragmatic here, knowing jQuery won't help you navigate the world the "kids" are busy building right now with frontend SPA frameworks. jQuery obviously has it's place, and if you prefer using it then no one can stop you. I just don't agree that it's better, and I don't believe it's as useful to know for new developers with the way the industry is changing.