javascript change innerhtml

javascript change innerhtml

Rather than assigning var1 to window.onload, youre currently calling the function and storing its result. Also, this might be obvious, but var1 seems like an odd name for a function. Try this:

function var1() {
  document.getElementById(text).innerHTML = hi;
}

window.onload = var1;

Note the casing of onload, as well as the missing parentheses after var1.

correct:

window.onload = var1;

in your example value of window.onload is undefined because function var1 returns nothing (undefined). You should set onload property to function var1, not result of calling function var1()

javascript change innerhtml

using .innerHTML is non-standard, and a terrible practice for many reasons. you should create a new element using the proper standard methods and and add it to the tree where you want it

Leave a Reply

Your email address will not be published.