Can I use Javascript to change the td content in a table? | Sololearn: Learn to code for FREE!

0

Can I use Javascript to change the td content in a table?

I have tr (with an id="one") and 3 td's, with text "Over", "Under" and "Between", respectively. After selecting the tr element using document.getElementById("one"), how do I change say "Between" to "Through" ?

10/10/2018 10:58:31 PM

Stan Berger

6 Answers

New Answer

+1

https://www.w3schools.com/jsref/prop_html_innerhtml.asp

+1

// Assuming element "Between" is the third td element. document.querySelectorAll("#one td")[2].innerText = "Through";

+1

Calvin, thank you! Why does trip.childnodes[2].innertext = not work?

+1

childNodes

0

I started with var trips = document.getElementById("one") then var arr = trips.childNodes then arr[2].innerHTML = "Through"; ** Wanted to understand why this approach is incorrect**

0

Please note that whitespace and text is considered as nodes and comments are also considered as nodes.