Welcome to my website and this is Saibal with yet another post to share my knowledge with you all.
For selecting single element:
element = document.querySelector(selector);
For selecting multiple elements:
elementList = document.querySelectorAll(selectors);
Great, but here comes the tricky part when using querySelectorAll returns a NodeList object, which doesn't provide any array functions like push, map, forEach which makes working at ease. Now there's a cool trick to achieve it.
elementList = Array.from(document.querySelectorAll(selectors));
Now, the NodeList gets transformed to an array which works great and make use of the array functions.
There are other cool functions that are worth checking and useful in terms of performance and more specific too.
Happy learning folks!