Autofocus on input field when div slides down

穿精又带淫゛_ 提交于 2019-12-03 10:52:59

You can use slideDown's callback function which is executed when animation is complete.

$("#status_comments_"+a).slideDown(function(){
    $("#comment_field").focus();
});

Note that IDs must be unique, otherwise your ID selector only selects the first element with that specific ID. If input element is within the div tag you can also code:

$("#status_comments_"+a).slideDown(function(){
    $('input', this).focus();
});
user5004402
 $("#divId").show().focus();

document.getElementById('divID').focus();

hidden field cannot gain focus ..so what you need to do is on click of button you have to show them .

$("#status_comments_"+a).show().slideDown();
    $("#comment_field").show().focus();
user5004402
$("#divID").focus();

or without jQuery:

document.getElementById('divID').focus();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!