Home >>jQuery Tutorial >jQuery select() Method

jQuery select() Method

jQuery select() Method

jQuery select() method in jQuery is used to add a function or triggers the select event to run, when a select event occurs in a text area or a text field.

Syntax:

Trigger the select event for the selected elements:

$(selector).select()

Attach a function to the select event:

$(selector).select(function)s

Parameter Values

Parameter Description
function It is an optional parameter and used to specifies the function to run when the select event is triggered
Here is an Example of jQuery select() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").select(function(){
alert("Text marked!");
});
});
</script>
</head>
<body>
<input type="text" value="Hello Phptpoint">
<p>Select some text inside the input field</p>
</body>
</html>

Output:

Select some text inside the input field


No Sidebar ads