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 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,252 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