views:

498

answers:

4

Hey there! Sorry, but for some reason my call to each() always fails, and "this[0].innerHTML is undefined" shows up in fire bug. The code isn't particularly complicated and it seems to follow all the examples I've seen so far.

Would anybody have an idea as to why this would fail?

$("#theirItems tbody tr").each(function(i){
       var child = $(this);
       if(child.children("td").size() < 6){
        //Unimportant stuff
       }
});

It fails on the first line, where it calls the each function.

Thanks in advance!

A: 

My hunch is that the children() method or the size() method is undefined for one or more iterations of the each() statement. Try the following:

...
var children = child.children();
console.log(children);
var size = children.size();
console.log(size);

if (size < 6) {
...
jkndrkn
A: 

does

if($(child).children("td").size() < 6) { }

also cause this error?

John Boker
A: 

Evan, your code is correct and should not throw an error, so I would check a few things:

  1. Use the latest version of jQuery
  2. Check for additional libraries on the page like Prototype or MooTools. It is somewhat possible you are not even using the jQuery .each and are using a MooTools .each. If this is the case, put jQuery in no conflict mode by calling jQuery.noConflict() and using jQuery in place of $
Doug Neiner
+1  A: 

Hey all, I'm so sorry to trouble you all, I was just being incredibly obtuse.

There was an error in the "unimportant stuff," and for some reason it was going to that error in Firebug early so I didn't spot it (it jumped to the jquery library as soon as it hit the each line and showed the error.

Thank you very much everyone fr your assistance, I hope I can return the favor somewhere along the way.

Evan