Converting jQuery to vanilla JS

preview_player
Показать описание
LINKS

Рекомендации по теме
Комментарии
Автор

I love the pragmatic pointer of using `querySelector()` for muscle memory, rather than getElementById() for the negligible performance difference.

Not 100% where I found it, but for looping over a NodeList I've been doing:

```js
Array.prototype.forEach.call(listOfNodes, (elem) => { });
```

Should I give more consideration to the NodeList foreach() method or a for...of loop?

BradCzerniak
Автор

I usually put 2 functions like this in my code

function $(selector, element=document) {
return
}

function $$(selector, element=document) {
return
}

nathnolt
Автор

I still love jQuery and still use it. I don't see a noticeable performance gain by not using it. "Because it's old" just doesn't seem to be a good reason not to use it. Most of HTML is "old" too. But I do think it's good to teach new people on vanilla JS first.

briankgarland
Автор

It would be nice to explain the difference between "display:none" and the hidden attribute, because it's not the same thing. Choosing to change the way it's hidden is (I think) outside the scope of converting to vanilla JS.
Also, does the use of "for...of" free you of having to check for an empty result from querySelector()?

thinkjoyously
Автор

so there is no an instant jQuery to vanilla javascript converter?

hamodi