Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Mobile Drop Down Menu Perfect

John McKinney
John McKinney
15,331 Points

Can't figure out why my selector is still showing up and I can't click it

I can't click the box and make it show any options

Here's my JS:

//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 options that are those links
  var $option = $('<option></option>');  
  //Deal with selected option depending on current page
  if($anchor.parent().hasClass('selected')) {
    $option.prop('selected', true);
  }
  //option's text is the text of those links
    //Create options that are those links
  $option.val($anchor.attr('href'));
  $option.text($anchor.text());
  //append option to select
  $select.append($option);
});

//Bind click to the select
$select.change(function(){
   //Go to select's location
  window.location = $select.val();
});

2 Answers

John McKinney
John McKinney
15,331 Points

Figured out what I did wrong, I forgot the # before menu in the $('#menu a')

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,065 Points

Hi John,

This might be too simplistic an answer but I noticed on your CSS the min-width:320px value is greyed out. So it might not be picking up that media query properly.

@media (min-width: 320px) and (max-width: 568px) {
  #menu ul {
    display:none;
  }
}

Try putting a space after the colon as shown above and check it out. :-)

John McKinney
John McKinney
15,331 Points

Just tried that and it didn't fix it, thanks though