Ivan Ivan - 2 months ago 9
CSS Question

jQuery click function fires up on page load

I'v been trying to figure this out on my own and searched up on google but I don't know what the problem is, the click function keeps firing up on page load. Please explain the problem and how to fix it. Thanks.

$(document).ready(function(){

$('.menu-icon').click(function(){
$('.menu-nav').animate({
height: 'toggle'
}, 200
);
});
});

Answer

Its not firing on page load. It has to do with your css rather than javascript code. Javascript is working as expected. You need to set menu hidden when the page loads for the first time. Please see this

https://jsfiddle.net/vatsalpande/zmoko9yk/1/

Add

display:none to .menu-nav

Hope this helps.

Happy Learning

Vatsal