Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to select all on focus in input using JQuery?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The select() event is applied to an element using jQuery when the user makes a text selection inside an element or on focus the element. This event is limited to some fields.

$("selected element").select();
//Select all Input field on focus
//Select Input field on focus whose type="text"
//Select input field using its id="input-field"

In below example, select all made on input element of the form using focus, focus and click event.

<!DOCTYPE html>
    <script src="
        input {
            margin: 12px;
        ::-moz-selection {
            /* Code for Firefox */
            color: white;
            background: red;
        ::selection {
            color: white;
            background: red;
<body align="center">
    <form action="/action_page.php" 
        First name:
        <input type="text" 
        <br> Last name:
        <input type="text"
        <br> E-mail:
        <input type="email" 
               value="" />
        <br> Password:
        <input type="password" 
               required maxlength="8">
        <br> User Age:
        <input type="number" 
        <br> Your web Profile:
        <input type="url" 
               required />
        <input type="submit" value="Submit">
        $("input[type='text']").on("click", function() {
        $("input").focus(function() {
        $("input").focusin(function() {


My Personal Notes arrow_drop_up
Last Updated : 31 Oct, 2019
Like Article
Save Article
Similar Reads
Related Tutorials