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


troy beckett
troy beckett
12,035 Points

Removing mobile nav when screen reaches certain width?

I want to remove my navigation menu when my screen reaches 750px +. Using jquery I thought this would work:

var $headerWidth = $("header").width();

if($headerWidth > 750) {
 $(".mobile-menu").css( "display", "none" );

however this isn't working. I think the code does work but I think I'm not calling it possibly what am I doing wrong guys?

2 Answers

anil rahman
anil rahman
7,786 Points

maybe just use a css media query, something like this as a base and change to what you like:

@media screen and (max-width: 1050px) {
    body:after {
        content: 'tablet';
        display: none;

On resize of the document window:

jQuery(window).resize(function() {
    var windowWidth;
    windowWidth = jQuery(window).width();
    if (windowWidth > 750) {
        jQuery(".mobile-menu").css( "display", "none" );