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 trialCory Wallace
14,313 Pointsthis 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); });
3 Answers
Jonathan Rhodes
8,086 Pointsi 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
231,275 PointsNeither 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
14,313 PointsYou guys were right, I totally missed the < on my opening option tag under line 12 . . . Thank you so very much!
Steven Parker
231,275 PointsSteven Parker
231,275 PointsWhen posting code, be sure to use the instructions for code formatting found in the Markdown Cheatsheet found below the "Add an Answer" area.