Event jQuery Select by Example

Learn jquery select() event by example. We take very simple example of select event.

jQuery select()

The select event occurs when a text is selected (marked) in the text field or text field. This event is limited to the field and box. When the select occurs, the select() method encloses a function to run.

Syntax

$(selector).select()  

It triggers a selected event for the selected elements.

$(selector).select(function)  

Parameters of jQuery select() event

ParameterDescription
FunctionIt is an optional parameter. It is used to specify the function to run when the select event is executed.

Let’s see example of jquery select event()

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("input").select(function(){
    alert("Text marked!");
  });
});
</script>
</head>
<body>

<input type="text" value="Hello World">

<p>Select some text inside the input field.</p>

</body>
</html>

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *