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

Can't understand..

Can't understand why $select.val() in

  window.location = $select.val();

returnes the current link... $select has this code:

<select>
</select>

It doesnt have any value.... $option has the value...

3 Answers

Pavle Lucic
Pavle Lucic
10,801 Points

Hi Alexey Tseitlin

The mission is to on click or on change event you go to another page. (That is purpose of having the menu).

So to do that, you first need to take url adress, from selected option value.

$select.val() do that. It returns select option value. (for example it returns "http://secondPage.html");

And after that you want to transfer to that destination (on http://secondPage.html); To do that, you need to use window.location property. Window.location is your boat to another location. So you need to tell your boat where you want to go. To do that use $select.val().

Tom Knox
Tom Knox
12,408 Points

Hi Alexy,

I had the same question, but I think I have figured it out. Since a select menu only allows a user to choose one option at a time, it gets its overall value from the value assigned to option the user chooses. This value is set behind the scenes when a user chooses an option in the list. It will not show up in the HTML markup since we are not writing this information to the page.

I hope this helps!

Placid Rodrigues
Placid Rodrigues
12,630 Points

Hi,

If you log $select.val() in console, you will get the value of selected option, such as "contact.html". It shows that the value of the select element is stored in the $select.val(). Therefore, since the value has the page name, window.location goes to that location.

Hope that helps. Placid