Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

jQuery Event Methods

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

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

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

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

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

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

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

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

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

//The on() Method
$("p").on("click", function(){
  $(this).hide();
});

//Example
$("p").on({
  mouseenter: function(){
    $(this).css("background-color", "lightgray");
  },
  mouseleave: function(){
    $(this).css("background-color", "lightblue");
  },
  click: function(){
    $(this).css("background-color", "yellow");
  }
});
 
PREVIOUS NEXT
Tagged: #jQuery #Event #Methods
ADD COMMENT
Topic
Name
1+1 =