Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jeremy Frimond
14,470 PointsWhat's the Method to get an element by its class?
What method do I use to get an element by its class?
For an ID we would do:
document.getElementById("")
so what do we do when it's a class we are after?
Cheers
2 Answers
Calvin Nix
43,828 PointsPersonally I just use JQuery :)
But for Javascript you could use the following...
document.getElementsByClassName(classname);
Laura Cressman
12,548 PointsTry document.getElementByClassName and let me know if that works!
Laura Cressman
12,548 PointsLaura Cressman
12,548 Pointswow beat me to it!
Calvin Nix
43,828 PointsCalvin Nix
43,828 Points*blows off smoking gun barrel and puts gun back in holster*:)Jeremy Frimond
14,470 PointsJeremy Frimond
14,470 PointsThanks I knew it was somewhere around there. Calvin Nix what do you use in Jquery?
$(".classname").whateverGoesNext?
Calvin Nix
43,828 PointsCalvin Nix
43,828 PointsYeah that is all you have to do. It makes life a lot easier.