+ 2
Can someone please tell me what's wrong?
4 Answers
+ 6
function clo(color){
var f = document.getElementById("first");
var s = document.getElementById("second");
s.style.background = color;
}
+ 4
Problem is because javascript part executes first, and in starting there is no element with those id's.
So put first two lines in function instead of outside or during onload in body..
+ 4
Problem was in Js.
Just declare both variables inside function.
+ 1
The js code is executed before the html dom is even loaded!
That's why it returns null and thus result in an error.
To prevent this add all the code inside this:
window.onload = function(){
// Here
}