Originally I was using input with an id and grabbing it's value with getElementById. Currently, I'm playing with <td>
s. How can I grab the values of the <td>
?
Originally I used:
<input id="hello"> document.getElementById("hello").value;
Now I want to get value of <td>
, but I don't know how;
<td id="test">Chicken</td> <td>Cow</td>
Edit: What's the difference between textContent
, innerHTML
, and innerText
?
jQuery: code to get TD text value on button click. So our code to get table td text value looks like as written below. $(document). ready(function(){ // code to read selected table row cell data (values).
td elements don't have value. What you are looking for is to get the value of the attribute value of that element.
$(document). ready(function(){ var r=$("#testing":row2). val(); alert(r); });
To get the text content
document.getElementById ( "tdid" ).innerText
or
document.getElementById ( "tdid" ).textContent var tdElem = document.getElementById ( "tdid" ); var tdText = tdElem.innerText | tdElem.textContent;
If you can use jQuery then you can use
$("#tdid").text();
To get the HTML content
var tdElem = document.getElementById ( "tdid" ); var tdText = tdElem.innerHTML;
in jQuery
$("#tdid").html();
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