Why not use javascript handlers on the body element?

Posted by disown on Stack Overflow See other posts from Stack Overflow or by disown
Published on 2010-04-28T11:19:48Z Indexed on 2010/04/28 11:23 UTC
Read the original article Hit count: 328

Filed under:
|
|
|
|

As an answer to the question of 'How do you automatically set the focus to a textbox when a web page loads?', Espo suggests using

<body onLoad="document.getElementById('<id>').focus();">

Ben Scheirman replies (without further explanation):

Any javascript book will tell you not to put handlers on the body element like that

Why would this be considered bad practice? In Espos answer, an 'override' problem is illustrated. Is this the only reason, or are there any other problems? Compatibility issues?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about body