Right now, I have this td:
<td id="setCustomer"><?= $customer ?></td>
Later down the page I have:
<script>
document.getElementById('setCustomer').onclick = function(){
var newOne = document.getElementById('setCustomer');
console.log("var newOne is "+newOne);
}
</script>
When I click the table cell that contains this customer name, the function launches and spits out:
var newOne is [object HTMLTableCellElement]
instead of:
var newOne is ACME CORP.
what am I doing wrong?
You need the content of the element, not the element itself:
var newOne = document.getElementById('setCustomer').innerHTML;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With