JQuery toggle () without animation, but full function?

I am trying to switch the visibility of an element without animation, but with a full function to change the link text that triggers the switch.

jQuery('.toggle_tags').click(function(){ var elem = jQuery(this); jQuery('#taglist').toggle({complete: function() { if (jQuery(this).is(':visible')) { elem.text('(Hide Tags)'); } else { elem.text('(View Tags)'); } },}); return false; }); 

Unfortunately, this still causes animation. Without ANY params, toggle is not animated, but even if you just pass only a function or a full function (as above), I still get the animation.

Any tips?

+4
source share
2 answers

Do not use the complete function.

Without parameters .toggle() will work synchronously, which means that you can simply check what he did in the following statement, knowing that it will already be completed, you can use:

 jQuery('#taglist').toggle(); if (jQuery('#taglist').is(':visible')) { elem.text('(Hide Tags)'); } else { elem.text('(View Tags)'); } 
+10
source

Try adding duration: 0 to the options object. More details in the docs

+2
source

All Articles