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 PointsNeed Help Evaluating a Jquery String
Can anyone explain why this string will not prepend my text:
$( document ).ready(function() {
$("#menu-employeenav li").hasClass( "current-menu-item" ).prepend("> >");
}
While this one will:
$( ".current-menu-item" ).prepend("> >");
I have multiple menus in my website. I dont want the >> to appear in all my menus so I am trying to be more specific.
EDIT: I changed the string order to has .hasClass() at the end and the quotes appear, but on all the li elements. is there a function that evaluates if a class is present vs the .hasClass() that gives the element the class? Cheers
2 Answers
Giuseppe Nardella
17,790 PointsTry this:
$("#menu-employeenav").children( "li.current-menu-item" ).prepend("> >");
Placid Rodrigues
12,630 PointsYour first code is missing a semicolon at the end. It will be
$( document ).ready(function() {
};