jquery - Changing a style element when a Class is clicked -
so have element without id using class name "optin-box" , have nav item class of "my-nav" has margin-top:46px. when click on optin box, want remove margin-top "my-nav" class
closest have got this:
$(".optin-box").on('click', (function(event) { $(".my-nav").removeattr("style"); console.log('firing'); });
or
$(".optin-box").click (function() { $(".my-nav").css('margin-top', '0 !important'); console.log('firing'); });
and tried variations cant work. console log outputs nav move @ all.
you forgot close (function(){})
, added )
end of function.
$(".optin-box").on('click', (function(event) { $(".my-nav").removeattr("style"); console.log('firing'); }));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="my-nav" style="margin-top:50px;">my-nav</div> <button type="button" class="optin-box">optin-box</button>
Comments
Post a Comment