Skip to content Skip to sidebar Skip to footer

Using Jquery Focus And Blur To Show And Hide A Message

I am clicking to set focus on a textbox, and once I have set focus I am trying to display a simple message. Then on blur that message disappears. Here is my code: If I click on the

Solution 1:

You need to trigger the focus event, instead of defining it. Try this instead:

<script>
$(function() { // Shorthand for $(document).ready(function() {
      $('#clicker').click(function() {
            $('#T1').focus(); // Trigger focus
      });

      $('#T1').focus(function() { // Define focus handler
            $('#myFocus').show();
      }).blur(function() {
            $('#myFocus').hide();
      });
});
</script>

Solution 2:

The problem is here:

$("#T1").focus(function(){            
      $("#myFocus").show();        
});

You should trigger the event with focus() not attach a callback with focus(function(){...}

Fixed code:

$(document).ready(function(){    
  $("#clicker").click(function(){        
        $('#T1').focus();
  });        

  $("#T1").blur(function(){        
      $("#myFocus").hide();    
  })     .focus(funcion(){
              $("#myFocus").show();        
          });
});

Post a Comment for "Using Jquery Focus And Blur To Show And Hide A Message"