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 1

nick vervaeke
nick vervaeke
16,422 Points

Why did I have to add $select.show().

To make it show up I had to add $select.show(). I'm using chromium on linux and since this is not featured in the tutorial, is this a change in the jquery api. I'm typing the code on my local computer and am using the files from the download section. I also tested the included js file. same problem. Any thoughts?

3 Answers

Steven Parker
Steven Parker
229,732 Points

It makes sense that you would need to call show on a hidden element to reveal it.

You might need to show specifically where in the code you had to add this line to make it possible to analyze the issue. There's a good chance this issue is caused by the HTML and/or CSS components setting the initial state to not be visible.

It might be particularly helpful if you mark your change with comments and then make a snapshot of your workspace and post the link to it here.


UPDATE: Now that I've seen the CSS code, you might want to change it if you don't need these items to be invisible initially:

@media (min-width: 568px) { #menu button { display:none; } }  /* removed "#menu select, " */
nick vervaeke
nick vervaeke
16,422 Points

As i can't copy on workspace, I couldn't paste from my local computer so I posted it here.

var $select = $("<select></select>");
$("#menu").append($select);
console.log("menu added?");

$("#menu a").each(function() {
    var $anchor = $(this);
    var $option = $("<option></option");

    $option.text($anchor.text());
    $option.val($anchor.attr("href"));

    $select.append($option);







});

var $button = $("<button>Go</button>");
$("#menu").append($button);

$button.click(function() {
    window.location = $select.val();


});

//before i added these it wouldn't show
$select.show();
$button.show();
Steven Parker
Steven Parker
229,732 Points

As I suggested before, you can share the entire workspace if you make a snapshot and post the link to it here.

Nothing in this JavaScript code would cause the show methods to be required. This issue is probably caused by the HTML and/or CSS componenets and a snapshot would share them all at once.

nick vervaeke
nick vervaeke
16,422 Points

I don't use workspaces. I prefer to code with vim. Anyway i figured it out. I was using the final version of the css.

@media (min-width: 320px) and (max-width: 568px) { #menu ul { display:none; } }

@media (min-width: 568px) { #menu select, #menu button { display:none; } }

I guess these two rules were responsible.

Steven Parker
Steven Parker
229,732 Points

Cool, so my guess about it being in the CSS was correct.

You might want to change the CSS if you don't need these items to be invisible initially. I updated my original answer with a suggested modification.