Use element.querySelector(). cy. They are much, much faster then looping over the whole DOM / wrapper, or pushing stuff into empty array. I think what I need is a cross browser getElementsByClassName or I need to use doc.getElementsByTagName('span') and loop through until I find class 4. Are new stars less pure as generations go by? Please confirm if you are able to. If parent is a slottable and is assigned, then set slottable to parent. Developer keeps underestimating tasks time, Can be followed by letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_"). Your comment was necessary. I do of course agree that a function to get whatever type of element at whatever index within an other element would be better, but I did no interpret the question like that... reading the question again I see that I totally misunderstood though :-), I use this technique frequently to get the first element eg document.getElementById("test").childNodes[0]. By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy. Follow answered Sep 2 '19 at 19:02. All published articles are simple and easy to understand and well tested in our development environment. Unexpected result when subtracting in a loop. The problem is that getElementsByClassName doesn't work in IE8. This will return the first element matching the class that is found. get ('input[name="firstName"]'). That's when it fails. For more info, visit: https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector. I have one question, What below selection will do? Use YAHOO.util.Dom.getElementsByClassName() from here. Also, sometimes we want any child that contains a className. What's the least destructive method of doing so? Returns: the CSS Path that can be used to retrieve the element in a selector. edit: or maybe I don't understand how that object works and it is just a normal dom object? Element attribute dictionary. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Convert getted result of InnerHTML text to an element, Javascript: retrieve hidden field value inside element with ID, select elements by class that have a specific child element with javascript, Multiple event handlers only firing on first element, not the target,