document queryselector picks first or last

Solutions on MaxInterview for document queryselector picks first or last by the best coders in the world

showing results for - "document queryselector picks first or last"
Aymen
29 Jun 2020
1var elFirst = document.querySelector(".myclass"); //first element
2var elLast = document.querySelector(".myclass:last-child"); //last element
3
4But be careful!
5:last-child and :first-child are relevant to the parent element, 
6not to the list! It means that there could be several first-childs 
7and several last-childs