html
html
1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body id="main">
<script>
<!-- write js code here if your js code is executing fastly then your html -->
</script>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
body {
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//const main = document.getElementById("body"); // not working
// the reason it is not working because your javascript code is get executed before the loading of your page
// solution 1: write your code in your html by using script tag
// solution 2 : don't store id use it like line No 15
// main.style.backgroundColor = "black"
// not work if you write this here
function time() {
//here, see below
document.getElementById("main").style.backgroundColor = "red";
}
setTimeout(time, 2000);
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run