04. jQuery Event Methods


jQuery Event Methods


<script>
//.....................................................................

$("p").click(function(){
  $(this).hide();
});

//.....................................................................

$("p").dblclick(function(){
  $(this).hide();
});

//.....................................................................

$("#p1").mouseenter(function(){
  alert("You entered p1!");
});

//.....................................................................

$("#p1").mouseleave(function(){
  alert("Bye! You now leave p1!");
});

//.....................................................................

$("#p1").mousedown(function(){
  alert("Mouse down over p1!");
});

//.....................................................................

$("#p1").mouseup(function(){
  alert("Mouse up over p1!");
});

//.....................................................................

The hover() method takes two functions and is a combination of the mouseenter() and 
mouseleave() methods.

$("#p1").hover(function(){
  alert("You entered p1!");
},
function(){
  alert("Bye! You now leave p1!");
});

//.....................................................................

The focus() method attaches an event handler function to an HTML form field. 
The function is executed when the form field gets focus:

$("input").focus(function(){
  $(this).css("background-color""#cccccc");
});

The function is executed when the form field loses focus:

$("input").blur(function(){
  $(this).css("background-color""#ffffff");
});

//.....................................................................

The on() method attaches one or more event handlers for the selected elements.

$("p").on("click"function(){
  $(this).hide();
});

$("p").on({
  mouseenter: function(){
    $(this).css("background-color""lightgray");
  },
  mouseleave: function(){
    $(this).css("background-color""lightblue");
  },
  click: function(){
    $(this).css("background-color""yellow");
  }
});       
</script>

Comments

Popular posts from this blog

09.Data Binding.

Database - Topics

02. Spring – Creating spring project clone it with GIT step by step.