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

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Perform: Part 1

Another problem with options not showing up in nav bar...?

I hate asking another one of these but it's hard to move on until I get this resolved.

The options aren't appearing in the navbar. Have stared at the code until my eyes bled...not sure if there's an error in my .js or .html but, can anyone check and see if there's an error in this code?

//Create a select and append to menu
var $select = $("<select></select>");
$("#menu").append($select);

//Cycle over menu links
$("menu a").each(function(){
  var $anchor = $(this);

  //Create an option
  var $option = $("<option></option>");

  //option's value is the href (i.e., href=index.html --> user sees "Home")
  $option.val($anchor.attr("href"));

  //option's text is the text of link (what I just said above)
  $option.text($anchor.text());

  //append option to select
  $select.append($option);
});
var $select = $("<select></select>");
$("#menu").append($select);

$("menu a").each(function(){
  var $anchor = $(this);

var $option = $("<option></option>");

$option.val($anchor.attr("href"));

 $option.text($anchor.text());

$select.append($option);
});

Edited out the comments for readability.

2 Answers

Brodey Newman
Brodey Newman
10,962 Points

Hello Brian!

Your problem is that you aren't selecting your 'menu' div properly.

Below is what your code should look like.

$("#menu a").each(function() {});

Hi Brodey, thank you! Amazing how you can look at something for so long and not see the obvious.