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 trialGaurav Raghuvanshy
10,672 PointsFailing 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
28,046 PointsHi 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
Mustafa Başaran
28,046 PointsHi 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');
Gaurav Raghuvanshy
10,672 PointsGaurav Raghuvanshy
10,672 PointsHello Mustafa,
Will this work?: var $button = $("<button>Go</button>");