Javascript Ajax jQuery Html PHP Example Quiz New MORE

jQuery select() method with example

The jQuery select event occurs when a text is marked or selected in text area or a text field. This event work only in <input type="text"> fields and <textarea> boxes. It is an inbuilt function of jQuery.

Syntax:

1. $(selector).select()
It triggers the select event for selected elements.
2. $(selector).select(function)
It adds a function to the select event.

Example:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Select Method</title> 
        <script src= 
        "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
        </script> 
          
        <!-- JQuery code to show the working of this method -->
        <script> 
            $(document).ready(function() { 
                $("input").select(function() { 
                    alert("Something was selected"); 
                }); 
                $("textarea").select(function() { 
                    alert("Something was selected"); 
                }); 
            }); 
        </script> 
        <style> 
            div { 
                width: 250px; 
                height: 40px; 
                padding: 20px; 
                
            } 
        </style> 
    </head> 
    <body> 
        <div> 
            <!-- select any thing from inside this field -->
            <input type="text" value="Student Tutorial!"> <br><br>
            <textarea rows="4" cols="50">At Student Tutorial!you will learn how to make a website. 
            </textarea>
        </div> 
    </body> 
</html> 


Run it Yourself »