0

I have a table in my index.html file

<table id="userTable">
      <tr>
        <th>UserId</th>
        <th>About you</th>
        <th>Age Max</th>
        <th>Age Min</th>
        <th>City</th>
      </tr>
</table>

Im using firebase to pull some data down to display it in the table.

  snapshot.forEach(snap => {
    console.log(snap.val())
    var r = document.getElementById('userTable').insertRow().innerHTML = snap.val().username
    var x = r.insertCell(1);
    x.innerHTML = snap.val().age
  })

The firebase logic is working correct, i am able to get the desired fields, but i can't seem to insert the data into a column for that row.

Im getting an error:

TypeError: r.insertCell is not a function. (In 'r.insertCell(1)', 'r.insertCell' is undefined)

The plan is to create a row and then populate the columns with the rest of the data.

1
  • 2
    What do you expect r to hold and why? Commented Nov 4, 2019 at 21:17

1 Answer 1

2

You have two assignments in this line:

var r = document.getElementById('userTable').insertRow().innerHTML = snap.val().username

I'm not sure what the value of r is in this case, but it's not a HTMLTableRowElement which is why you're getting that TypeError. You need to call insertCell on a HTMLTableRowElement object. See this documentation for more information: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableRowElement/insertCell

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.