Reputation: 70
My code is like so
function show_file(itemid) {
document.getElementById("itemid").innerHTML = "Testing";
}
<td id='$itemid' class='header-row'>
MyText quote
<button onclick='show_file($itemid)'>
Button<i class='fa fa-angle-down'></i>
</button>
</td>
But I get this error "Cannot set property 'innerHTML' of null" so it seems the value of $itemid is not getting passed?
Upvotes: 0
Views: 90
Reputation: 70
That is because you gived a string in parameter to your getElementById function and not the itemid variable. Try this :
function show_file(itemid) {
document.getElementById(itemid).innerHTML = "Testing";
}
Upvotes: 1
Reputation: 311
You should pass the actual function's parameter itemid
not the string "itemid"
Change it from:
function show_file(itemid) {
document.getElementById("itemid").innerHTML = "Testing";
}
To:
function show_file(itemid) {
document.getElementById(itemid).innerHTML = "Testing";
}
Upvotes: 1