Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 463
MonsterMMORPG Avatar asked Oct 02 '11 00:10

MonsterMMORPG


People also ask

How can add cursor in textbox using jQuery?

This can be done by using the focus() method and click() method. We will create a web page with a textbox and a button. We will add the functionality using jQuery such that on clicking the button, the cursor is set to the textbox.


1 Answers

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();`
});
like image 133
Jason Gennaro Avatar answered Sep 20 '22 14:09

Jason Gennaro