`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($('<span/>', {class: "input-group-addon", text: 'Auswählen'}));
});

Somehow I get this error in the first line:

Uncaught TypeError: undefined is not a function 

I tried something in the console to fix this problem! But for some reason, nothing happened!

Now I hope you help me! JSFIDDLE: http://jsfiddle.net/3C98M/

thank

+4
source share
4 answers

elementnot a jQuery object, the second argument to the function $.eachreturns its own 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 this classis a reserved keyword in javascript and should be specified.
It can 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.

+12
source

$(...)

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

element $() adeneo this:

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

(, ), , , , " " ( - ).

, Javascript-, $( jQuery) .

:

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

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

( , jQuery).

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

0

Source: https://habr.com/ru/post/1539173/


All Articles