Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert row is not a function

I am trying to display my results and I am getting an error: "insertRow is not a function. Not sure how I can fix this.

JS file:

function sayHelloCallback (response) {
   var table = document.getElementById("wheel");

   for(i = 0; i < response.message.length; i++)
   {
       var row = table.insertRow(0);
       var cell = row.insertCell(0);
       cell.innerHTML = response["message"][i];
   }
}

HTML File:

<div class="w3-container w3-padding-64 w3-center" id="salaries">
   <h2>View Salaries</h2>
   <p id="wheel">
       <i class="fa fa-spinner w3-spin" style="font-size:64px"></i>
   </p>
</div>

Please help.

like image 877
Demetrius Avatar asked Jun 24 '26 12:06

Demetrius


2 Answers

insertRow is a property of tables.

You are trying to call it on a paragraph.

If you want to add data to an arbitrary element, use appendChild.

like image 117
Quentin Avatar answered Jun 27 '26 01:06

Quentin


The HTMLTableElement.insertRow() method inserts a new row in the table and returns a reference to the new row.

Then insertRow() function should be called on HTMLTableElement, but the elment with the id wheel in your sample is a paragraph p and not a table.

like image 26
Zakaria Acharki Avatar answered Jun 27 '26 01:06

Zakaria Acharki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!