Skip to content Skip to sidebar Skip to footer

`find()` Undefined Is Not A Function

I have this little jquery function: $.each($('#TableBody tr:gt(0)'), function(index, element){ element.find('td').last().html($('', {class: 'input-group-addon', te

Solution 1:

element is not a jQuery object, the second argument of the $.each function returns the native DOM node

$.each($('#TableBody tr:gt(0)'), function(index, element){
    $(element).find('td').last().html($('<span/>', {"class": "input-group-addon", text: 'Auswählen'}));
});

Also note that class is a reserved keyword in javascript and should be quoted. It could also be written

$('#TableBody tr:gt(0)').each(function(index, element) {
      $(element).find('td').last().html(
          $('<span/>', {
              "class" : "input-group-addon", 
              text    : 'Auswählen'
          })
      );
});

which is more readable IMO.

Solution 2:

Surround element with $(...) to work

$(element).find('td:last')....

Solution 3:

Wrap element with $() like the adeneo's answer or simply using this:

$('#TableBody tr:gt(0)').each(function () {
    $(this).find('td:last').html($('<span/>', {
            "class" : "input-group-addon",
            text : 'Auswählen'
        }));
}));

Solution 4:

This is most likely not the answer to question of John Smith (very generic name by the way) but it hopefully will be relevant to users looking for the solution to the 'X is not a function' javascript error (for which this post is the top result).

It can be, that if you are loading multiple Javascript libraries, $ (shortcut for jQuery) get's overridden.

You could use:

jQuery(element).find('td:last')....

Instead of

 $(element).find('td:last')....

To solve this (or remove the library that overrides jQuery).

Source: http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/

Post a Comment for "`find()` Undefined Is Not A Function"