What are some reasons for jquery .focus() not working? -


some thoughts element_id.focus() inside divs hidden @ times.

this should easy problem solve -- i'm struggling :(

***code works fine -- 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? :(

you need either put code below html or load if using document load event:

<input type="text" id="goal-input" name="goal" /> <script type="text/javascript"> $(function(){     $("#goal-input").focus(); }); </script> 

update:

switching divs doesn't trigger document load event since have been loaded. need focus when switch div:

if (goal) {       step1.fadeout('fast', function() {           step1.hide();           step2.fadein('fast', function() {                 $("#name").focus();           });       }); } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -