How to check visibility state in jQuery toggle function?

Here is a quick tip how to check visibility state of a toggled element in jQuery:

$('#element').toggle('slow', function() {
  if($(this).is(':hidden')) {
    $(this).text('This element is hidden.');
  }
  else {
    $(this).text('This element is visible.');
  }
});


Tags: