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 trialEli Yazdi
3,639 Points"$button.click is not a function"
Hello!
I was just working through the video, and when I tried to run it, it didn't work when I clicked go. I checked and my code was exactly the same as his. Could anyone help me? Here's 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 appropriate 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 the href
$option.val($anchor.attr("href"));
// Option's text is the link's text
$option.text($anchor.text());
//Append option to select
$select.append($option);
});
//Create a button
var $button = ("<button>Go</button>");
$("#menu").append($button);
//Bind click to button
$button.click(function(){
window.location = $select.val();
});
//Modify CSS to hide links on small resolution and show button and select
//Also hides select and button on larger widths and shows links
//Deal with selected options depending on current page
Thank you!
3 Answers
Cory Madden
7,120 Pointsvar $button = ("<button>Go</button>");
Should read:
var $button = $("<button>Go</button>");
Chyno Deluxe
16,936 PointsDid you link to the jQuery library in your html file?
Eli Yazdi
3,639 PointsYes.
Dennis Brown
28,742 PointsThanks for asking this question! I'm not sure how that dollar sign got past me but it did. Chrome automatically added a breakpoint letting me know there was an error, but couldn't quite make the connection. ;)
Eli Yazdi
3,639 PointsEli Yazdi
3,639 PointsThank you so much!
(This is my first time using the Treehouse forums and I never guessed I would get such quick responses - it looks like everyone here is really helpful!)
Thanks again!