I'm trying to toggle an element's visibility without animation, but with a complete function so that I change the text of the link initiating the toggle.
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 is still triggering animation. Without ANY params, toggle doesn't animate but even either by passing just a function or the complete function verbosely (as above), I still get animation.
Any advice?
Don't use a complete
function.
Without parameters, .toggle()
will operate synchronously, meaning that you can just test what it did in the next statement, knowing that it will already have finished, you could use:
jQuery('#taglist').toggle();
if (jQuery('#taglist').is(':visible')) {
elem.text('(Hide Tags)');
} else {
elem.text('(View Tags)');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With