I have an HTML table with buttons in the fourth column. I want to be able to push each button and have it return the value in the second column, but same row.
I create the table using this code:
function loadTableData() {
for (i=0; i < 7; i++) {
let row = table.insertRow();
let scale = row.insertCell(0);
let note = row.insertCell(1);
let chord = row.insertCell(2);
let play = row.insertCell(3);
scale.innerHTML = degChoice[i]
note.innerHTML = finalArray[i];
chord.innerHTML = chordChoice[i];
play.innerHTML = '<button onclick="playAudio()">Play Chord</button>'
}
}
The table values are being generated based on other criteria (this part's working fine).
And this is the code I am using to try to call the value of the second cell in the row:
function playAudio(){
var firstCell = this.parentNode.parentNode.childNodes[1].nodeValue;
alert(firstCell);
}
No matter what I try, I can't return that second cell value. Does anyone have any advice for this?