From jQuery JavaScript Library
« 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.
Examples:| Name | Type |
To trigger the select event on all input elements, try:
$("input").select();
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:| fn | Function | |
|---|
A function to bind to the select event on each of the matched elements.
function callback(eventObject) {
this; // dom element
}
|
Examples:| Name | Type |
To do something when text in input boxes is selected:
$(document).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="../jquery-latest.js"></script>
<script>
$(document).ready(function(){
$(document).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>