ドキュメント

Events/select

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Events

select( )

Trigger the select event of each matched element.
This causes all of the functions that have been bound to that select event to be executed, and calls the browser's default select action on the matching element(s). This default action can be prevented by returning false from one of the functions bound to the select event. Note: Do not confuse the "select" event with the "change" event, which is the one triggered when an html "select" element is having its selected option modified by the user.
Examples:

To trigger the select event on all input elements, try:

$("input").select();

NameType

select( fn )

Bind a function to the select event of each matched element.
The select event fires when a user selects some text in a text field, including input and textarea.
Arguments:
fnFunction
A function to bind to the select event on each of the matched elements.
function callback(eventObject) {
  this; // dom element
}
Examples:

To do something when text in input boxes is selected:

    $(":input").select( function () { 
      $("div").text("Something was selected").show().fadeOut(1000); 
    });

<!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(){
    
    $(":input").select( function () { 
      $("div").text("Something was selected").show().fadeOut(1000); 
    });

  });
  </script>
  <style>
  p { color:blue; }
  div { color:red; }
  </style>
</head>
<body>
  <p>
    Click and drag the mouse to select text in the inputs.
  </p>
  <input type="text" value="Some text" />
  <input type="text" value="to test on" />
  <div></div>
</body>
</html>

NameType