Javascript deletes html and css?

I dont think its the best question and perhaps its simple, but cant figure it.

my code:

css :

h2 {
color: red;

document.body.innerHTML = ‘hi’

my javascript can only be seen, but when i delete my javascript my html and css can be seen when i run it on the browser. Why is this? Am i missing something on the link tag? Everything is also in one root folder. Is this a common problem. why cant they both be seen on the browser?


1 Like

That script effectively wipes out everything in the body element and replaces it with raw, untagged text. The screen will be white with just the word, hi displaying.


Thank you,

i just need to change that script,

do you have any suggestions?

1 Like

First rule, make sure all the HTML is well formed and validates…

Don’t write any script until the HTML and CSS are both valid.

What is it you expect the script to do? We really only need script to perform tasks that cannot be done any other way.

1 Like

i just want to practice my javascript but at the same time practice my html and css.

i expected the script to join up my js to my html and css…

it points to an external script file through the src attribute. just wanted to try and make a website…both displaying my html, css and javascript

1 Like

What do you have for HTML?

1 Like

what do you mean? like html5 or you want to see my html code?

1 Like

Yes, that’s it. Post your HTML document.

1 Like