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
jose macedo
6,041 Pointsjquery help
why is my current option not showing in my selecter.. height calapsed in my selected ..
this is my jquery code
//create a select element
var $select = $("<select></select>");
//append select to #navigation
$("#navigation").append($select);
//cycle threw each alink and create a function.
$("#navigation a").each(function() {
var $anchor = $(this);
//create a option
var $option = $("<option></option>");
if($anchor.parent().hasClass("selected")) {
$option.prop("selected", true);
}
//options val is the href value
$option.val($anchor.attr("href"));
//options text is the text of links
$option.text($anchor.text());
//apend option to select
$select.append($option);
});
// create a button bind click to button
var $button = $("<button>go</button>");
$("#navigation").append($button);
$button.click(function(){
//to go to selects location
window.location = $select.val();
});
1 Answer
Steven Parker
243,658 PointsThe problem is not in your JavaScript/jQuery code.
It's more likely something in your HTML or CSS, neither of which is not shown here.
It's always a good idea to provide the complete code, properly formatted, or a snapshot of your workspace.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 Pointsformatted code