Search code examples
javascriptmouseovermouseout

Fade effect when mouse over and out


I need to add Fade effect on mouseover and out.

$(document).ready(function(){
    $("#txtchange").mouseover(function (){
        $('#txtchange').text("My New Txt");
    });
    $("#txtchange").mouseout(function (){
        $('#txtchange').text("Old Txt");
    });
});

Solution

  • Try with below code

        $(document).ready(function(){    
           $("#txtchange").mouseover(function (){
               $("#txtchange").fadeOut(function() {
                 $(this).text("My New Txt").fadeIn();
               });
           });    
           $("#txtchange").mouseout(function (){
              $("#txtchange").fadeOut(function() {
                $(this).text("Old Txt").fadeIn();
              });   
           });    
      });