Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS jQuery Basics (2014) Creating a Mobile Drop Down Menu Perform: Part 1

Uncaught TypeError: $option.val is not a function

this is an error my console is showing up, i've review the video, side by side and dont see any differences...

Hi Vladimir,

Can you post your code or a snapshot if you're using workspaces?

https://teamtreehouse.com/forum/workspace-snapshots

Ali Asgar
Ali Asgar
2,112 Points

i got the same error and after half and hour of struggling and staring the code and then going to the discussion forums , i realized that i missed the $ sign. Arghhhhhhhhhhh!!!!!

5 Answers

WHOAAAAAA MAN, thanksssssssssssssssss alot, you just saved my life, I can sleep in peace today!!!!!!!!!!!! incredible how a simple thing can ruin a whole code... Works perfectly Again, thanks a lot!!!!!!1

You're welcome. I'm glad you can get some good sleep now.

Jason Anello, man, honestly don't know how to post the code... :(, have been trying to post a snapshot but dont see how...

// Problem: looks gross in smaller browser and small devices width. //Solution: Make a drop down menu, for smaller devices

//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 values are the href of the links

HERE IS WHERE JS SHOWS THE ERROR... $option.val($anchor.attr("href"));

//OPtions text are the texts of the links $option.text($anchor.text());

//Append OPtions to Select $select.append($option);

});

//Create button

Here it goes the is the code...

Hi Vladimir,

For posting snapshots you can check the link I gave above. It's easy to do once you check it out.

One problem I see in your code is that you're not actually creating an option element with this line:

 var $option = ("");

You want to create an option element wrapped in a jQuery object like this:

 var $option = $("<option></option>");

This is done at about the 5:00 mark in the video linked to if you want to review it.

There could be other problems but fix that first and let me know where you're at.

Hi there again, I've checked, and have corrected the $option (not creating and option element...) but still doesn't work, and its driving me crazy, I've checked it hundred times and dont see the mistake... here is the snapshot... By the way, thanks a lot for the quick response!!!!!

Snapshot: https://w.trhou.se/9ivrgyuu4w

You're still missing the dollar sign $ in front of

("<option></option>")

There's 2 $ symbols in the code.