jQuery Tutorial


jQuery Example


jQuery References


jQuery focus() Event Reference


  jQuery Events References


Uses

jQuery focus() event Occurs when the element gets focus.


Bind a Function to focus() event

Defined function run when the focus() event occurs on the selected elements.

Syntax

$(selector).focus(function) 

jQuery focus() events supported following parameters.

ParameterDescription
functionFunction is Optional parameter. Function define the ready to run when event occur.

Example

<script type="text/javascript"> 
$(document).ready(function(){
  $("input").focus(function(){
    $("input").css("background-color","#FFFF99");
  });
  $("input").blur(function(){
    $("input").css("background-color","pink");
  });
});
</script>
Online Try This Code Your Self....   »

Trigger the focus() event

Triggering the focus event for a selected elements.

Syntax

$(selector).focus() 

Example

<script type="text/javascript"> 
$(document).ready(function(){
  $("input").focus(function(){
    $("input").css("background-color","#FFFF99");
  });
  $("input").blur(function(){
    $("input").css("background-color","pink");
  });
  $("#btn1").click(function(){
    $("input").focus();
  });  
  $("#btn2").click(function(){
    $("input").blur();
  });   
});
</script>
Online Try This Code Your Self....   »

  jQuery Events References