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
Douglas Dunn
8,937 PointsAll my options disappear except the home option when I added the if statement. Help!
$("#menu ul li a").each(function() { var $anchorText = $(this).text(); var $option = $("<option></option>");
$option.text($anchorText);
$select.append($option);
var $optionValue = $(this).attr("href");
$option.val($optionValue);
if (this.parent().hasClass("selected"))
{
$option.prop("selected", true);
}
});
1 Answer
Steven Parker
243,656 PointsWhere you have this:
if (this.parent().hasClass("selected")) {
Perhaps that should be:
if ($(this).parent().hasClass("selected")) {
Douglas Dunn
8,937 PointsDouglas Dunn
8,937 PointsThanks! That was the solution to my problem!