Sebastiano Sebastiano - 1 month ago 5
jQuery Question

Change CSS display on windows resize and toggle

When i use the toggle function and i resize the window the nav still display none, and this resize function doesn't work, any advises ?

$(document).ready(function(){ $("#menu").click(function() { $( ".nav" ).fadeToggle("slow", "linear");});

$(window).resize(function() { if ($(window).width() < 768) { $('.nav').css("display", "none");} else {$('.nav').css("display", "inline-block");}});});


I also want when the click is not on the nav bar desappear, actually desappear only when i click on the svg icon, i try this code but it doesn't work.

$(document).click(function(event) {if(!$(event.target).is('#menu')) {$(".nav").hide();}});


Here the live page https://sebalaini.github.io/NewPortfolio/
and here the repo https://github.com/sebalaini/NewPortfolio

Answer

It looks like you missed a period:

Try

$('.nav').css("display", "inline-block");

Instead of

$('nav').css("display", "inline-block");

jQuery is looking for a nav tag instead of a .nav class.

Comments