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
Stephen Ford
2,836 PointsSelectBox and Button only visible on Home page.
The select bar is in place, the options are in it, the button functions and on the .click, the page is refreshed to the new selected page.
Issue: the SelectBox and Button are only visible on the Home page. This makes the SelectBox only usable when the user is already on the home page.
Is there anyone else running into this issue? Any suggestions are welcome.
JQuery
//Problem the site is not small device friendly
//Solution: replace menu bar items with a select box and button
//create a select and append to #menu
var $select = $("<select></select>");
$("#menu").append($select);
//loop over menu links
$("#menu a").each(function(){
var $anchor = $(this);
//create an option
var $option = $("<option></option>");
//options value = href
$option.val($anchor.attr("href"));
//option text = text of link
$option.text($anchor.text());
//append option to select box
$select.append($option);
});
//create button
var $button = $("<button>GO</button>");
$("#menu").append($button);
//bind click
$button.click(function(){
//go to selected location
window.location = $select.val();//getting value of selected option
});
1 Answer
Jonathan Grieve
Treehouse Moderator 91,254 PointsI wonder if there's a simple explanation, Have you included the jquery and CSS fles on all the html pages?
Stephen Ford
2,836 PointsJonathan, your asking about the other HTML pages got me thinking.
I had to change the script src link to make the program run as in it's initial state the program gave an error. I had replaced the code on the index.html page and the error went away, or at least I thought, I did not recheck to see if the error would reappear if I changed pages.
I went back and added the new script src tag in all the HTML files and the problem was solved!
Nice work!
Though I need to amend my prior statement. All the pages are now showing the box and button except for the support page. Even though the script src tag is the same as all the others. :/ hmm
Stephen Ford
2,836 PointsStephen Ford
2,836 Pointsthe var $option is not showing the interior of it's () on this page but rest assured the code... for the option is there :)