Is there a way to search the DOM for an element with a particular stylename class? Something like:
var node = document.findByClassName("foo");
if so, will this be extremely slow if my page has like 2000 elements in it or so?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the browser does not support the native method you can sift through every tag and look for the class names. This version allows you to specify a parent to search from and more than one class can be matched. It returns an array of nodes in either case, not a ‘live’ nodelist.
// use-
/*IE9 will have support for the native method, and versions of IE below 8,
as well as some other older browsers, will fall back to the sifting method.
You can add a quicker method than the sifter to IE8.
*/