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

Menu items does not get checked when clicked

After following the video, my menu items does not get checked when click, even on both chrome and mozilla This actually in the jQuery Course in the drop down tutorial section.

Someone pls help.

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


//cycle over the menu
$("#menu a").each(function(){
var $anchor = $(this);
//create an option
var $option = $("<option></option>");

  //deal with selected options on current page
  if($anchor.parent().hasClass("selected")){
    $option.prop("selected", true);
  }


  //option's value is the href
  $option.val($anchor.attr("href"));
  //option text is the text of link
  $option.text($anchor.text());
  //append option to select
  $select.append($option);

});

//Craete button to click to go to select location
var $button = $("<button>Go</button>");
$("#menu").append($button);
//bind click to button
$button.click(function(){
  //Go to select's location
  window.location = $select.val();
});

Can you post your code?

I have done that @Stephen O'Connor.

Thank you

Not sure which video you're referring to, you might want to add some additional relevant tags so people know which course, video, etc. you're referring to. You might also want to add JavaScript as one of your thread's topic tags since your problem has to do with JavaScript. Could you also paste the code for your HTML?