4th Aug 2020, 2:48 PM
Purple Requiem
Purple Requiem - avatar
4 Answers
+ 6
function clo(color){ var f = document.getElementById("first"); var s = document.getElementById("second"); s.style.background = color; }
4th Aug 2020, 2:53 PM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 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..
4th Aug 2020, 2:52 PM
AKSHAY🇼🇳
AKSHAY🇼🇳 - avatar
+ 4
Problem was in Js. Just declare both variables inside function.
4th Aug 2020, 2:52 PM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 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 }
5th Aug 2020, 5:57 AM
MSN
MSN - avatar