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" ?

10th Oct 2018, 10:58 PM
Stan Berger
Stan Berger - avatar
6 ответов
+ 1
// Assuming element "Between" is the third td element. document.querySelectorAll("#one td")[2].innerText = "Through";
11th Oct 2018, 12:35 AM
Calviղ
Calviղ - avatar
+ 1
Calvin, thank you! Why does trip.childnodes[2].innertext = not work?
11th Oct 2018, 12:46 AM
Stan Berger
Stan Berger - avatar
+ 1
childNodes
11th Oct 2018, 12:59 AM
Calviղ
Calviղ - avatar
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**
11th Oct 2018, 2:22 AM
Stan Berger
Stan Berger - avatar
0
Please note that whitespace and text is considered as nodes and comments are also considered as nodes.
11th Oct 2018, 3:06 AM
Calviղ
Calviղ - avatar