I am trying to focus on the username input in my login screen to allow for easier access to logging in and currently my jquery looks like this
$(document).ready(function() {
$('#Username').focus();
});
but that doesn't work... any ideas?
I am trying to focus on the username input in my login screen to allow for easier access to logging in and currently my jquery looks like this
$(document).ready(function() {
$('#Username').focus();
});
but that doesn't work... any ideas?
Does the tag have an id attribute?
<input id="Username" name="Username" type="text" />
I'm guessing it only has a name attribute:
<input name="Username" type="text" />
If you can't add the ID attribute, you can select it like this:
$("input[name='Username']").focus();
It does work in the following simple example. Therefore there is something else going on on your page that causes the input to lose focus. I suggest using setTimeout to set the focus.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test!</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#Username').focus();
});
</script>
</head>
<body>
<input id="Username" />
</body>
</html>