jquery - Stop page from jumping to top on click with if else -
I have a button that is toggling my menu (# menu-toggle) when the user clicks on the button So the page jumps on top
tried it but it is not working:
$ ('# menu-toggle'). Click (function) ($. 'Rap, nav' gt; ul, .rope & gt; container: first-child '). ToggleClass (' push '); event.preventDefault (); if ($ ($ '' ('$' ''. '' ('$' ''. '' '' $ '' ('' Wrap ''). Css ('position', 'fixed'); $ ('rape & gt; container: first-child> div: first-child' Here is my html:
SlideUp (500);} and {$ ('. Rap'). CSS ('position', 'relative');}}) < / P>
& lt; button id = "menu-toggle"> gt; id = "new-toggle"> gt; & lt; / span & Gt; & lt; / div & gt; & lt; / button & gt; Button ID = "search-toggle" & gt; & lt; / button & gt;
Any help would be appreciated.
Thanks
< After completing a solution
else block
, return falls e or event.preventDefault () / Strong > And if statement is not , then you can use something like this: $ ('# menu-toggle'). Click (Function (Event) ($ ('.rape, NAV; UL, WOP & gt; Container: First-child'). ToggleClass ('push'); if ($ ('. Rap'). Push ')) {$ (' rap '). CSS (' position ',' fixed '); $ (' wrap 'gt; container: first-child & gt; div: first-child' '). 500);} and {$ ('rap'). CSS ('position', 'relative');} event.preventDefault (); // is equivalent to returning false;});
Comments
Post a Comment