jQuery Form How to - Fade button text when clicking








Question

We would like to know how to fade button text when clicking.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from   w  w  w.ja  v a 2  s  .c o  m-->
    $('#slideButton').click(function()
    {
        $(this).find('span').html('Collapse').hide().fadeIn('slow');
    });
});
</script>
</head>
<body>
  <button id="slideButton" type="button">
    <span>Expand</span>
  </button>
</body>
</html>

The code above is rendered as follows: