javascript - Function inside a function is not working -


i working on responsive design , made function menu change when smaller 540px (meant mobile). change cant click button , guess is because of function inside function.

this part doesn't work:

  $('.menuknop').click(function(){       $(".menu").slidetoggle();   }); 

full code:

checkwidth(){     var windowsize = $(window).width();     if (windowsize < 540) {         $(".menu").hide();         $(".menuknop").show();          $('.menuknop').click(function(){             $(".menu").slidetoggle();         });     }     else {         $(".menuknop").hide();         $(".menu").show();     } }  //execute function checkwidth(); $(window).resize(checkwidth); 

is want?

working demo

 $('.menuknop').click(function(){       $(".menu").slidetoggle();   }); function checkwidth(){     var windowsize = $(window).width();     if (windowsize < 540) {         $(".menu").hide();         $(".menuknop").show();     }     else {         $(".menuknop").hide();         $(".menu").show();     } }  $(window).resize(checkwidth); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -