Search code examples
jqueryparent

JQuery: pass $(this).parent(); to method?


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]
    });