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

window.location

My window won't change when i press the "Go" button - is my code wrong?:

//Problem: It looks Gross in small devices like a phone
//Solution: Hide text links and replace with more appropriate links

//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 an Option
  var $option = $("<option></option>");

  //Options Value is the href of the Link
  $option.val($anchor.attr("href"));
  //Options Text is the Text of Link
  $option.text($anchor.text());
  //Append Option to Select
  $select.append($option);
  })

//Create a Button
var $button = ("<button>Go</button>");
$("#menu").append($button);
  //Bind Click to Button
  $button.click(function() {
    //Go to Select location
    window.location = $select.val();
    });

4 Answers

The most apparent thing I notice is that, when you build the button element, you aren't using jQuery. You have:

var $button = ("<button>Go</button>")

instead of:

var $button = $("<button>Go</button>")

Perhaps use "window.location.assign($select.val());"

No that wasn't it but thanks for the try!!

Aaron, that was it - it's always something small, but that's why i like coding....like putting a puzzle together.

thanks!

Any time. I have spent hours debugging when it turned out to be a simple spelling mistake.

Happy coding!