Quick Reach
jQuery select
As some text is selected inside a text box or text area of your web page, the jQuery select event occurs. You can use the jQuery select method to perform some action as the select event occurs.
Syntax of using select method
The simple syntax of using select jQuery method is:
$(“selector”).select(function());
A select method example
This example shows when the jQuery select event occurs inside a text box, an alert will be shown by using the select method. For the select event to occur, select some text inside the text field.
Experience this example online
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<html>
<head>
<script src=“http://code.jquery.com/jquery-1.10.1.min.js”></script>
<script>
$(document).ready(function(){
$(“#selex”).select(function(){
alert(“Select event occured!”);
});
});
</script>
</head>
<body>
<input type=“text” id=“selex” value=“Select some text here”>
</body>
</html>
|
Example of select method in text area
The following example shows select method triggering an alert as the select event occurs inside text area field by using the select method of jQuery. For the select event to happen, select some text inside the textarea.
Experience this example online
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<html>
<head>
<script src=“http://code.jquery.com/jquery-1.10.1.min.js”></script>
<script>
$(document).ready(function(){
$(“#selex”).select(function(){
alert(“Select event occured!”);
});
});
</script>
</head>
<body>
<textarea id=“selex” rows=“10” cols=“20”>Select some text here! Select some text here ! Select some text here “>
</textarea>
</body>
</html>
|
Also see jQuery slide | jQuery events
Leave A Comment?