Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Building A Dynamic Table For Portfolio Page

Hi,

I'm trying to build a dynamic table to hold images for my portfolio page. I'm pulling in the data from a CMS. After every three images, I would like a new table row. I'm currently using mithril.js as my MVC framework. Here is the function I've created:

this.three = function(data) {
           for(var i = 0; i < this.projects().length; i++){
               if(i % 3 == 0) {   //after every third cell add a new row and change the row variable to point to it
                 row = table.insertRow();
               }
               var cell = row.insertCell(-1);  //simply insert the row
               cell.innerHTML = items[i];
            };
        }

this.projects() is the response data from my AJAX call.

my issue is that I keep receiving an error that reads Uncaught TypeError: table.insertRow is not a function

i'm unsure as to why this method is throwing an error - and if you have suggestions for a more elegant solution, i'm interested in that, too!

2 Answers

Maybe it is because you didn't define the table in table.insertRow()

Maybe it is because you didn't define the table in table.insertRow()