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 3

edmond habimana
PLUS
edmond habimana
Courses Plus Student 8,352 Points

#menu ul still being displayed in smaller window.

CSS:

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

@media (min-width: 568px){
  #menu select, #menu button{
    display:none;
  }
}

Jquery:

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

//Cycle over menu links



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

     //a.create an option
var $option = $("<option></option>"); 

    //b.option's value is the href
var $hrefValue = $(this).attr("href");
  //the code below not the best option to set the value of option in the select element.
//$option.attr("href",$hrefValue);  ************

  //better option below.
  $option.val($hrefValue);

    //c.option's text is the text of link
var $linkText = $(this).text();
$option.text($linkText);

    //d.append option to select
$selectMenu.append($option);

  var $parent = $(this).parent();
  if($parent.hasClass("selected")){

    $option.prop("selected",true);
  }



})


//create a button
var $button = $("<button>button</button>");
//append the button to the div with an id ="menu"
$("#menu").append($button);

//bind click to button
$button.click(function(){
    //Go to select's location

  window.location = $selectMenu.val();
    //Deal with select option depending on the current page

})

2 Answers

Damien Watson
Damien Watson
27,419 Points

Just a quick one, is it because you are missing the 'px' on the max-width item?

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