0

Good evening everyone.

I am new to Javascript and am not understanding something probably very basic.

Can someone please tell me why I am not allowed to assign a new value of empty string to a variable using:

variable = "";

in the following code :

https://jsfiddle.net/58rztr71/2/

I have checked and the IF statement is working since I can use "alert("hi")" and it does alert Hi but trying to assign a new value is just not doing anything.

Sorry if my question is very stupid but i just don't get it...

  • You are assigning the value, but you aren't doing anything with it. – SLaks Oct 24 '17 at 20:51
  • Oh ok. I thought this would reallocate the empty string value to the H1 box and update the content. How do i get the content to overwrite the current content then? :( (basically...how do i make the Hello text on the HTML disappear and replace it with the "" content?) – Chris Redfield Oct 24 '17 at 20:52
  • document.getElementById('content').innerHTML = "" – juvian Oct 24 '17 at 20:55
  • Oh ok indeed if i add : document.getElementById('content').innerHTML = h1Content; it does work indeed. Is this the proper way to update the HTML content though or is it "dirty code"? I just don't want to get into too many habits from the start... – Chris Redfield Oct 24 '17 at 20:55

0 Answers0