Search code examples
jquerytextboxtext-cursor

How set cursor inside textbox after page load with jquery


Alright i have a asp.net textbox and i want to set cursor inside textbox after page loaded like when you open google.

I only need set cursor inside textbox code.

I tried this but not working

$('txtSendTo').focus();

Solution

  • If txtSendTo is an id, you need a #

    $('#txtSendTo').focus();


    If txtSendTo is a class, you need a .

    $('.txtSendTo').focus();


    Or, if there is only one textbox on the page

    $('textbox').focus();


    Also make sure the page is fully loaded before you try to search the dom:

    $(document).ready(function () {
      `$('textbox').focus();`
    });