jQuery reverting CSS back to original state -
i have added click event using jquery change css. click works , css changes, jquery continues run , reverts css original state.
jquery code:
$('.myclass').click(function(){ $('.myclass').css({"visibility":"hidden"}); });
css code:
.myclass { height: 10px; width: 10px; background: red; visibility:visible; }
like said, click works , element gets hidden. however, reverts instantly when jquery finishes running through code. using google chrome's debugger tool, see point in jquery code reverts css having element visible.
jquery's code (line 4116):
if ( !(eventhandle = elemdata.handle) ) { eventhandle = elemdata.handle = function( e ) { // discard second event of jquery.event.trigger() , // when event called after page has unloaded return typeof jquery !== strundefined && jquery.event.triggered !== e.type ? line 4116 jquery.event.dispatch.apply( elem, arguments ) : undefined; }; }
i guess don't understand happening jquery code , why css gets reverted back? in understanding appreciated.
you might try toggling class has 'visibility:hidden' avoid issue altogether.
#css .vh{ visibility:hidden #or use display:none } #javascript $('.myclass').click(function(){ $('.myclass').toggleclass('vh'); });
let me know if helped you. -mike
Comments
Post a Comment