JQuery: pass $(this).parent(); to method?
Question
I have a simple script:
$('.expand').each(function(i){
var _Expand = $(this).parent();
ExpGroupBy(_Expand);
});
Trying to pass the <tr>
of all <td>
with the class 'expand'
However firebug keeps popping up the Error:
'TypeError: formObj.getElementsByTagName is not a function'
Any ideas?
Thanks ^^
Solution
As long as the function understands that the parameter is the jQuery object and not the DOM element itself. If the function expects a DOM element reference, you can easily do that like this...
$('.expand').each(function(i){
var _Expand = $(this).parent();
ExpGroupBy(_Expand[0]); // Note the [0]
});
OTHER TIPS
parent()
returns a jQuery object. Try this instead:
$(".expand").parent().each(function() {
ExpGroupBy(this);
});
If ExpGroupBy expects DOM element call it as ExpGroupBy(_Expand[0])
get(0) returns the element encapsulated in jquery object. You can use _Expand.get(0) as well
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow