1
I’m trying to pick the background color of a div
through a script.
That is, my goal is that as soon as the page appears it has already run the script and has appeared the color that the script has selected.
My question for now is:
<body onload="funcaoquemudaacor()">
Apparently, the parameter onload it doesn’t feel right, and it’s not working.
Is that my mistake? Solutions?
Why not use CSS? Really
onload
will only load the Javascript function after loading thebody
. An alternative is to make the content of the page invisible and after clicking make it visible with the desired color.– Paulo
Because the script is that will choose the css that will use, to be able to change the background color of the div as the case... I will try, thanks.
– Ana
More details are needed to give you a coherent answer to what you want to do. HTML will be produced dynamically by your Javascript, or the page is delivered already containing HTML and Javascript should change the color as soon as possible?
– Gabriel Gartz
If there is no way to add the color in the HTML generation by the server, an alternative is to hide the element by default, then when the page loads, change the color and show the element.
– utluiz
Vote today! Vote tomorrow! Vote always! Vote consciously! Your vote is very important to our community, contribute to us, and help make Stack Overflow in Portuguese (Sopt) bigger and bigger. You can learn more at: Vote early, vote often
– Victor Stafusa