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 3

Failing to create Go Button

Hello everyone,

Have been following the videos, but am unable to create a button. Heres my code:

//Create a button to go to select's location var $button = $("<button>Go</button>"); $("menu").append($button);

// Bind click to button to $button.click(function() { //Go to select's location window.location = $select.val(); });

Thank you for your time

2 Answers

Mustafa Başaran
Mustafa Başaran
28,046 Points

Hi Gaurav,

Before appending it to $('#menu') and binding it to a click event, you should create an HTML element.. and that is the button itself:

var $button = $("<button>Go</button>");

Would this work for you? The rest of your code is same as mine on the workspace.

It is the same logic with other jQuery lectures. We first create HTML elements, append them to the parts of the body that we want and then add interactivity through events.

Best regards,

Mustafa

Hello Mustafa,

Will this work?: var $button = $("<button>Go</button>");

Mustafa Başaran
Mustafa Başaran
28,046 Points

Hi Gaurav,

This form field erases html tags... it also occured in my reply. I have just noticed it. Sorry. So, I have to rephrase without tags. It looks a bit funny without the tags...

var $button = $('button-tag GO close-button-tag');