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
Richard Hope
25,237 PointsAdding class to element with jquery in wordpress
I'm trying to increase the height on my horizontal menu if the current menu item has children. Since I'm using wordpress the relevant classes are added to the menu but the code below doesn't seem to work. Can anyone suggest how I get this working? The below is everything in my js file:
$(function() { $(".current-menu-item.menu-item-has-children").$(".level-1").addClass("sub-menu-height"); }
1 Answer
Gary Calhoun
10,317 PointsHi try this looks like your closing curly brace wasn't before your semi colon and you forgot to close the parenthesis
$(function() { $(".current-menu-item.menu-item-has-children").$(".level-1").addClass("sub-menu-height")});
Richard Hope
25,237 PointsRichard Hope
25,237 PointsThanks. You were right- the code wasn't closed properly. The function bit at the beginning also needed amending since it was wordpress. Even then I had to change things round a bit. This was the code I used in the end:
jQuery(document).ready(function($) { if( $(".menu-item").hasClass("current-menu-parent")) { $(".level-1").addClass("menu-height"); } });
Gary Calhoun
10,317 PointsGary Calhoun
10,317 PointsNice glad you were able to get it working