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 2

Uncaught TypeError: $select.append is not a function

At the end of the video, I previewed my code and it did not have the same result as Andrew's result. When I checked the console, here is the error that they gave me:

Uncaught TypeError: $select.append is not a function (app.js:17)

I compared the 17th line on my code with the code in the video and they seem identical to me? Am I not able to see the error on line 17 or is the error on another spot that is messing up line 17?

Here is my code:

 //Problem: It looks gross in smaller browser widths and small devices
//Solution: To hide the text links and swap them out with a more apropriate navigation

//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 href of link
  $option.val($anchor.attr('href'));
  //Option's text is the text of the link
  $option.text($anchor.text());
  //append option to select
  $select.append($option);
});
//Create button to click to go to select's location
var $button = $("<button>GO</button>");
$("#menu").append($button);
//Bind click to button 
$button.click(function() {
  //Go to select's location
  window.location = $select.val();
});
//Modify CSS to hide links in small resolution and show button and select
  //Also hides select and button on larger width and show's links
//Deal with selected options depending on current page
$anchor.text();

Thanks, Ayush

Sorry ignore the last line containing $anchor.text();

2 Answers

In your code you're using var $select = ( "<select></select>"); This is not selecting the select element because you forgot $ before ( "<select></select>"); So this line should look like var $select = $( "<select></select>");

p.s. for the sake of making the code look neater you should remove the space before the double quotes on that line too.

Scott Evans
Scott Evans
4,236 Points

If I'm not Mistaken,

You should also initialise your 'select' with a $.

So

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