Some thoughts are that the ELEMENT_ID.focus() is inside divs that are hidden at certain times.
This should be an easy problem to solve -- but I'm struggling :(
***code works fine -- the text field isn't being focused on upon page loading up.
STEP1 [SOLVED]
JAVASCRIPT:
$("#goal-input").focus();
$('#goal-input').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13') {
etc, etc, etc
}
HTML
<input type="text" id="goal-input" name="goal" />
[STEP2]
JAVASCRIPT:
if (goal) {
step1.fadeOut('fast', function() {
step1.hide();
step2.fadeIn('fast');
etc, etc
HTML:
<div id="step-2">
<div class="notifications">
</div>
<input type="text" id="name" name="name" placeholder="Name" />
<script type="text/javascript">
$(function(){
$("#name").focus();
});
</script>
Why doesn't step 2 work? :(
question from:
https://stackoverflow.com/questions/9596419/what-are-some-reasons-for-jquery-focus-not-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…