Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  68] [ 7]  / answers: 1 / hits: 16844  / 10 Years ago, wed, november 19, 2014, 12:00:00

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?


More From » html

 Answers
33

You need the content of the element, not the element itself:



var newOne = document.getElementById('setCustomer').innerHTML;

[#68755] Monday, November 17, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ignacio

Total Points: 467
Total Questions: 128
Total Answers: 79

Location: Luxembourg
Member since Tue, Mar 14, 2023
1 Year ago
ignacio questions
;