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
Adam Wright
968 PointsJquery selecting double barrel class or id's
Hi guys,
I am working on a project with jquery and gsap, i am trying to target an an icons class to add a click function with jquery. The class is a double barrel name Example:
<i class="fas fa-caret-right"></i> i can target single name but cant seem to find on the docs how to target a double.
The first fas class would be var $clickRight = $(".fas") ;
Any help would be appreciated :)
2 Answers
Maxwell Newberry
7,693 PointsIf you want to select different elements with different classes you can do:
$('.classOne, .classTwo').doSomething();
See jQuery documentation on Multiple Selector.
Or, if you wanted to select one element with multiple classes for specificity you can do like you have in:
$('.classOne.classTwo').doSomething();
It really depends on what you're doing.
Edit: Changed for better clarification.
Adam Wright
968 PointsOh ok fasCaretRight?
Maxwell Newberry
7,693 PointsSo you're saying if you reference that class via $('.fas.fa-caret-right').doSomething();, it doesn't work?
Adam Wright
968 PointsAdam Wright
968 PointsHi thanks for the reply,
I understand how you do that, so I wanted to target fas-caret-right
If I just removed the - marks it doesn’t seem to work?
Would your html class tags be written in camel case too?