Nick W
Nick W

Reputation: 11

.innerHTML doesn't work inside function

document.getElementById("boxoffice[0][total]").innerHTML = "Working";
function totaltest() {
 document.getElementById("boxoffice[0][total]").innerHTML = "Not Working";
}

For some reason, the above innerHTML works perfectly OUTSIDE a function, but not inside...any ideas as to the cause??

Upvotes: 1

Views: 671

Answers (2)

Raman Sahasi
Raman Sahasi

Reputation: 31841

Are you sure that you're calling totaltest(), because the code that you've posted is completely valid.

See the following code, it works fine:

document.getElementById("aa").innerHTML = "test 1";

function totaltest() {
    document.getElementById("bb").innerHTML = "test 2";
}

totaltest();
<p id="aa"></p><br>
<p id="bb"></p>

Upvotes: 3

David
David

Reputation: 1159

You should do

document.getElementById("boxoffice[0][total]").innerHTML = "Working";
function totaltest() {
 document.getElementById("boxoffice[0][total]").innerHTML = "Not Working";
}
totaltest()

its not working because you are not invoking totaltest

Upvotes: 1

Related Questions