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

$(this) is returning "this.empty is not a function".

Here is my code:

var $Select = $("<select></select>");
$("#menu").append($Select);

$("#menu a").each(
  function()
  {
    var $Anchor = $(this);
    var $Option = $("<option></option>)");  

    $Option.val($Anchor.attr("href"));
    $Option.text($Anchor.text);    

    $Select.append($Option);
  });

The select box is turning up, but it doesn't contain any options to select from. The console is giving me the error: "Uncaught TypeError: this.empty is not a function".

What is happening?

2 Answers

Stefan Dietz
Stefan Dietz
2,360 Points

$Anchor.text is a method and not a property, so you need to call it in this way: $Anchor.text()

Hope this helps.

Lance McCormick
Lance McCormick
7,553 Points

Also... var $Option = $("<option></option>)"); ...should be... var $Option = $("<option></option>"); ...You had an extra " ) " closing round brace before the ending double quote mark.