A.M
A.M

Reputation: 63

Error in my jquery Code `Uncaught TypeError: Cannot call method 'eq' of null`

Please mention the error in this code.

$("#gridTable tr").eq(1).find('td').forEach( function(){//some code here});

I have tried different selectors but nothing worked.

I also tried using just id of specific row but same error with message that:

Cannot call method find of null.

On:

$("#firstRow").find('td').forEach( function(){//some code here});

Upvotes: 0

Views: 333

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074959

In each case, the error is telling you that $("#gridTable tr") returned null.

This suggests you're not using jQuery, but instead Prototype or MooTools (or something else entirely). jQuery's $() function will never return null, but both Prototype and MooTools' $() function will, if they don't find an element with the given ID. If you're using Prototype or MooTools, note that $() doesn't take a selector like jQuery's does, it takes an id. So you wouldn't use the # on it, and couldn't pass in a descendant combinator as you are in your example. (The nearest equivalent in Prototype to jQuery's $ is $$.)


Separately, if you were using jQuery, jQuery objects don't have forEach; they do have each which is similar (but the order of the arguments to your iterator function is different).

Upvotes: 3

Related Questions