Maybe my questions are stupid because I am beginner in JavaScript
Why is there is
classList
but there's notidList
Why do some people prefer to use
getElementById
instead ofgetElementByClassName
Maybe my questions are stupid because I am beginner in JavaScript
Why is there is classList
but there's not idList
Why do some people prefer to use getElementById
instead of getElementByClassName
Question 1: Every element can only have 1 id so there is no need for a list.
Question 2: getElementByClassName is not a function. getElementsByClassName is (notice the plural "elements"). getElementsByClassName returns a list of elements while getElementById returns only one element. Use getElementsByClassName is better when you want to get multiple elements.
I would recommend querySelector and querySelectorAll. They take CSS selector queries instead.
Question 1: Every element can only have one id, hence there is no requirement for an idList.
Question 2: You can read this . However, there are times where the id selector can outperform the class selector in speed. Which one to use (getElementById or getElementsByClassName) in these circumstances is up to you.