Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
They both refer to elements in the DOM. Every element in the DOM (usually declared with HTML) can have an Id or be part of a Class of elements. In the JavaScript if you use getElememtById() it will return the element with that Id while using getElementsByClassName() will return an array with all the elements of that class.
17th May 2020, 6:55 PM
Alessandro Palazzolo
Alessandro Palazzolo - avatar
+ 1
It will return an array with only one element
17th May 2020, 8:44 PM
Alessandro Palazzolo
Alessandro Palazzolo - avatar
+ 1
Yeah, thanks for pointing out that Dilyorbek Valijonov ! By the way it returns an array-like object so for basic operations you can treat it as an array, like accessing elements with the brackets notation. Abhay Rao
18th May 2020, 9:23 AM
Alessandro Palazzolo
Alessandro Palazzolo - avatar