0

i want to put this button

<button class="btn btn-primary btn-fab btn-icon btn-round">

Inside the column called "Details"

enter image description here

But i dont know how, this is my code

var tableRef = document.getElementById('ticker_table').getElementsByTagName('tbody')[0];
    var tickerArray = [];

    for (i = 0; i < 10; i++) {
        var newRow = tableRef.insertRow();
        newRow.insertCell(0).appendChild(document.createTextNode(data[i]["ticker"]));
        newRow.insertCell(1).appendChild(document.createTextNode(data[i]["fund"]));
        newRow.insertCell(2).appendChild(document.createTextNode(data[i]["index_tracked"]));
        newRow.insertCell(3).appendChild(document.createTextNode(data[i]["assetclass"]));
     }
DeathInWhite
  • 177
  • 1
  • 3
  • 12

1 Answers1

1

Rather than creating a text note, you could use the insertAdjacentHTML to add data before the end :

var tableRef = document.getElementById('ticker_table').getElementsByTagName('tbody')[0];
var tickerArray = [];

for (i = 0; i < 10; i++) {
    var newRow = tableRef.insertRow();  newRow.insertCell(0).appendChild(document.createTextNode(data[i]["ticker"]));
    newRow.insertCell(1).appendChild(document.createTextNode(data[i]["fund"]));
    newRow.insertCell(2).appendChild(document.createTextNode(data[i]["index_tracked"]));
    newRow.insertCell(3).appendChild(document.createTextNode(data[i]["assetclass"]));
    newRow.insertCell(4).insertAdjacentHTML('beforeend', '<button class="btn btn-primary btn-fab btn-icon btn-round">');
 }

Please refer to this answer for more informations about the insertAdjacentHTML function

Nicolas
  • 8,077
  • 4
  • 21
  • 51