Reputation: 242
I have an input field loaded with AJAX. I need that this field receives the focus when loading the page.
How to do it using jQuery, with the functions: LIVE and FOCUS?
Upvotes: 0
Views: 131
Reputation: 21473
$(document).ready(function() {
$('#yourfield').live('focus',function()
{
// do your stuff here
});
});
As pointed out, live
is deprecated as of jQuery 1.7, you should use on
in 1.7+:
$(document).ready(function() {
$(document).on('focus','#yourfield',function()
{
// do your stuff here
});
});
Upvotes: 1
Reputation: 5986
$(document).ready(function() {
$(document).on('focus', '#yourfield' ,function()
{
//your actions here
});
});
where document is before on() itself could be replaced with any parent element of #yourfield.
More info here: http://api.jquery.com/on/
Upvotes: 1
Reputation: 2044
Do you mean on page load like so or when the field is updated set focus to the field?
$(document).ready(function() {
$('#yourfield').focus();
});
Upvotes: 0