user516883 user516883 - 1 year ago 113
jQuery Question

jquery how to set input focus on control

Hey I am very new to jquery using, and I was wondering how to set focus on a textbox using jquery.

I have my script in my HeaderContent but it is not working, no focus on load. And yes I know this can be done on the server side as well, but I am just trying to get better and more familiar with jquery. Thanks.

<script type="text/javascript">
$(document).ready(function () {

Answer Source

Your code is correct. If it is failing, chances are $("#MainContent_LoginUser_UserName") is not the correct selector value or perhaps jQuery is not correctly loaded.

If you are using jQuery alongside standard ASP.NET JavaScript, then the '$' will not be mapped to jQuery, but instead to ASP.NET's JavaScript framework. You may need to substitute $("#foo") for jQuery("#foo").

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download