Javascript get element index position in DOM array by class or id
问题 My situation var domElements = document.body.getElementsByTagName('*'); Now I want to return the array item key - position of the element in the array - ( for example domElements[34] ) searching in the array for the element with id="asd" . How can I achieve this? What if instead of ID I want to search trough class="asd hey" ? Any help appreciated, thank you! NB: Not in jquery, I need it in pure javascript in this case 回答1: Try like this var matches = document.querySelectorAll("#asd"); If you