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 1

Cory Wallace
Cory Wallace
14,313 Points

this doesn't work

I've followed your code EXACTLY. I've even taken a snippit of your code to compare, side by side, with my code; and I am not receiving the same results as you. Here is my code Below:

//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 the link $option.text($anchor.text()); //append option to select $select.append($option); });

and here is your code:

//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>");

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

Steven Parker
Steven Parker
231,275 Points

When posting code, be sure to use the instructions for code formatting found in the Markdown Cheatsheet found below the "Add an Answer" area. :arrow_heading_down:

3 Answers

Jonathan Rhodes
Jonathan Rhodes
8,086 Points

i don't know specifically what results you are getting, but with a glance at your code, when you are defining $option, you are missing an "<" in the selector, so jQuery does not select anything to assign to that variable.

Steven Parker
Steven Parker
231,275 Points

Neither of these code excerpts is correct.

In the "my code" snippet you are missing a "<" character on this line:

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

And in the "your code" section, you have the name "opton" instead of "option":

$opton.text($anchor.text()); 
Cory Wallace
Cory Wallace
14,313 Points

You guys were right, I totally missed the < on my opening option tag under line 12 . . . Thank you so very much!