ドキュメント

Events/mousedown

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Events

mousedown( fn )

Binds a function to the mousedown event of each matched element.
The mousedown event fires when the pointing device button is pressed over an element.
Arguments:
fnFunction
A function to bind to the mousedown event on each of the matched elements.
function callback(eventObject) {
  this; // dom element
}
Examples:

Show texts when mouseup and mousedown event triggering.

    $("p").mouseup(function(){
      $(this).append('<span style="color:#F00;">Mouse up.</span>');
    }).mousedown(function(){
      $(this).append('<span style="color:#00F;">Mouse down.</span>');
    });

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    
    $("p").mouseup(function(){
      $(this).append('<span style="color:#F00;">Mouse up.</span>');
    }).mousedown(function(){
      $(this).append('<span style="color:#00F;">Mouse down.</span>');
    });

  });
  </script>
  
</head>
<body>
  <p>Press mouse and release here.</p>

</body>
</html>

NameType