Change body backgroundcolor on page load

Change body backgroundcolor on page load

Hello there,

i want to animate the backgroundcolor of the <body> when the page is loaded. It works - but sometimes when i switch from one page to another or if i just reload a page, it doesnt change.

First i used this script:

<script>
      $(window).load(function(){
        $("body").animate({ backgroundColor: "#bdc58f" }, 1000);
      });
    </script>


Now i thought it may work more reliable with this one:

<script>
      $(document).ready(function(){
        $("body").animate({ backgroundColor: "#bdc58f" }, 1000);
      });
    </script>


But it doesn't make any difference - both are working generally, but sometimes if i load a page it doesnt change the color.

Would be great if somebody could help me how to make the animation work reliable without failures.

Kind regards,

Christian

Edit: Recognized right now that i posted in the wrong forum - should have been posted in "Help, I'm stuck" - sorry!