jQuery | select() with Examples

The select() method is an inbuilt method in jQuery which is used when some letters or words are selected (or marked) in a text area or a text field.

Syntax:

$(selector).select(function);

Parameter: This method accepts single parameter function which is optional. Th function parameter will run after select method call.

Return Value: This method returns a notification when something is select.

Below example illustrates the select() method in jQuery:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>Select Method</title>
        <script src=
        </script>
          
        <!-- JQuery code to show the working of this method -->
        <script>
            $(document).ready(function() {
                $("input").select(function() {
                    alert("Something was selected");
                });
            });
        </script>
        <style>
            div {
                width: 250px;
                height: 40px;
                padding: 20px;
                border: 2px solid green;
            }
        </style>
    </head>
    <body>
        <div>
            <!-- select any thing from inside this field -->
            <input type="text" value="GeeksforGeeks!">
        </div>
    </body>
</html>

chevron_right


Output:
Before select anything !

After selecting some letters or words !



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.