ドキュメント

Events/dblclick

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Events

dblclick( )

Triggers the dblclick event of each matched element.
This causes all of the functions that have been bound to that dblclick event to be executed, and calls the browser's default dblclick action on the matching element(s). This default action can be prevented by returning false from one of the functions bound to the dblclick event. The dblclick event usually fires when the pointing device button is double clicked over an element.

dblclick( fn )

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

To bind a "Hello World!" alert box the dblclick event on every paragraph on the page:

$("p").dblclick( function () { alert("Hello World!"); });

Double click to toggle background color.

    var divdbl = $("div:first");
    divdbl.dblclick(function () { 
      divdbl.toggleClass('dbl'); 
    });


<!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(){
    
    var divdbl = $("div:first");
    divdbl.dblclick(function () { 
      divdbl.toggleClass('dbl'); 
    });


  });
  </script>
  <style>
  div { background:blue;
        color:white;
        height:100px;
        width:150px;
 }
  div.dbl { background:yellow;color:black; }
  </style>
</head>
<body>
  <div></div><span>Double click the block</span>
</body>
</html>

NameType