treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] How to change styles on onload=

  • I know this is a stupid question that I should know, but how do you change two style rules for the same element at one time on onload? I have this, but I want to add opacity:0; to it.

    onload="javascript:document.getElementById('loader').style.visibility='hidden';"
  • onload="javascript:document.getElementById('loader').style.visibility='hidden';document.getElementById('loader').style.opacity='0';"

    That should work.

    It would be better not to mix HTML with javascript like that though. Try this instead:
    <script type="text/javascript">
    window.onload = function(){
    var loader = document.getElementById('loader');
    loader.style.visibility='hidden';
    loader.style.opacity='0';
    };
    </script>
  • put it into a function



    window.onload = pre_loader;

    function pre_loader() {
    javascript:document.getElementById('loader').style.visibility='hidden';
    javascript:document.getElementById('loader').style.opacity=0;

    }


    I don't think IE support opacity though.
  • Thank You!!!!
    -Cliff