From the course: JavaScript: Enhancing the DOM

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Isolating elements by class name

Isolating elements by class name

From the course: JavaScript: Enhancing the DOM

Start my 1-month free trial

Isolating elements by class name

So far, we've looked at picking elements by ID and tag name. So, you're probably thinking that you can also pick elements by class name, and you would be right, sort of. The getElementsByClassName function is a bit of a new addition. Of course, it does that you select that elements with a specific class, but because it is a newer selector it is incompatible with older browsers. Whenever you have a question about whether a browser has support for a method, you should check out a couple of web pages. This one right here called caniuse.com is a really good resource. So, if you scroll down you can see that this method has support in pretty much every modern browser but not older versions of IE. Another page you should check out is the W3C.ompatibilty. If you scroll down on this page see you can get to the same information on the get element by class name method. Now, I'm using a pretty modern browser here this is a late version of Chrome so you shouldn't have a problem with this method…

Contents