jQuery mousedown() Method

jQuery mousedown() event occurs when a mouse left button is pressed down on the selected element. The jQuery mousedown method triggers the mousedown event, and when the event occurs specified function will execute.

This method is usually used together with the mouseup() method.

Syntax

This syntax represent to the mousedown() method

$(selector).mousedown();        // This syntax does not accept any arguments.

and this syntax represent to attach a function to the mousedown event

$(selector).mousedown(function);
Parameter Type Description
function Function Optional. Specifies the function to execute when the mousedown is occurs

Examples

This example represent the mousedown event

$(document).ready(function(){
  $("input").mousedown(function(){
    $("input").css("background-color", "yellow");
  });
  $("input").mouseup(function(){
    $("input").css("background-color", "pink");
  });
  $("#btn1").click(function(){
    $("input").mousedown();
  });  
  $("#btn2").click(function(){
    $("input").mouseup();
  });
});

Run it...   »


This example represent to attach a function to the mousedown event.

$(document).ready(function(){
  $("input").mousedown(function(){
    $("input").css("background-color", "yellow");
  });
  $("input").mouseup(function(){
    $("input").css("background-color", "pink");
  });
});

Run it...   »