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

Franklin Colbert
Franklin Colbert
4,868 Points

I cannot get my select menu to highlight the selected class:

not sure what I've missed here's my code

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

// cycle through menu links
$("#menu a").each(function(){
  var $anchor = $("#menu");

  if ($anchor.parent().hasClass("selected")) {
    $option.prop("selected", true);

  };
//  var $anchor = $(this);
  //create an option
var $option = $("<option></option>");



  // options value = href
  $option.val($(this).attr("href"));


  // options text = text of link
  $option.text($(this).text());


  // append option to select menu

  $select.append($option);

});
 $select.change(function(){
    window.location = $select.val();

  });

1 Answer

you need to write

3 back sticks (```) then js.

then line break and enter your code.

line break again and type another 3 back sticks(```)

Franklin Colbert
Franklin Colbert
4,868 Points

thank you, I think it was the lack of line break that was causing it to not display!