Reputation: 6259
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 some things in the console to fix this problem! But somehow nothing worked!
Now i hope you can help me! JSFIDDLE: http://jsfiddle.net/3C98M/
Thanks
Upvotes: 4
Views: 12991
Reputation: 7288
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/
Upvotes: 0
Reputation: 8553
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'
}));
}));
Upvotes: 1
Reputation: 4043
Surround element with $(...)
to work
$(element).find('td:last')....
Upvotes: 3
Reputation: 318182
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.
Upvotes: 13