[Javascript] CSS and Javascript

Paul Novitski paul at novitskisoftware.com
Sun Apr 3 07:52:27 CDT 2005


At 01:57 AM 4/3/2005, Abyss wrote:
>Im trying to (with complete failur) to hide a span  when the page loads

Abyss,

Put this into your javascript file:

         indow.onload = showHideSelection;

Then you don't have to put anything into your body tag.

The main criticism of the window.onload technique is that you can do it 
only once; repeat calls overwrite rather than accumulate onload 
functions.  One solution is to create a kind of onload function pool to 
which you add calls as needed:

         window.onload = function () {
                 initMouseOvers();
                 initSpanBehavior();
         }
[Ref: 
<http://www.digital-web.com/articles/separating_behavior_and_structure_2/>]

Recently I came across a niftier solution (wish I could remember where!) 
which I think went like this:

         window.onload = function()
         {
                 if (window.onload)
                 {
                         window.onload();
                         showHideSelection();
                 }
                 else
                 {
                         showHideSelection();
                 }
         }

This naturally concatenates onload functions and lets several external 
javascript functions start up on page-load without stepping on one 
another's toes.

Paul

PS: Not a good idea to post javascript questions to the CSS-D list.  This 
question doesn't really pertain to CSS. 





More information about the Javascript mailing list