Why there are somany other ways to get elements? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why there are somany other ways to get elements?

Why there are somany other ways to get elements even if there are Id(s), classes, first child etc....

12th Nov 2016, 6:02 PM
Mohi
Mohi - avatar
2 Answers
+ 4
In different situations you may need to use different ways. js makes it possible to reach the same element or elements with many functions
13th Nov 2016, 12:05 AM
David
David - avatar
+ 2
There's a bunch of reasons. Example: Sometimes you need to target a parent of a particular element that is dynamic by selecting only if the element contains a certain string. You'd have to target only the parent of that particular element. However, as a best practice, when possible choose to select by ID rather than class as js can find the element fastest that way.
30th Dec 2016, 6:29 PM
Veronica Furukawa
Veronica Furukawa - avatar