html - javascript focus not working on load -


window.onload = function() {                  try{                       document.getelementbyid('result').focus();                  }catch(err){                   }               } 

in form div result id load when form submits , when show want focus on it. above code not working in case. please me find problem code.
jsfiddle

here's working jsfiddle.


1. give div tab index of 0 (meaning ordered first):

<div class="result" tabindex="0" id="result"> 

(find out more tabindex property here.)

2. remove <script> tags:

window.onload = function() {     try{         document.getelementbyid('result').focus();     }catch(err){      }                     } 

3. use no wrap in <head> instead of onload.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -