views:

568

answers:

3
jQuery('td[class=bgoff]').each(function() {
    var td = jQuery(this);
    ... no apply selector to "this" only
});

I'm working with tabular data in html and trying to parse the contents of each TD (they are not uniquely identifiable).

Using XPath, I can prepend the path of "this" to additional selecting.

How can I achieve this with jQuery?

+6  A: 

With jQuery you have the option of supplying a second parameter after the selector expression and that becomes a context that jQuery uses to limit scope of the lookup. Learn more here

Scott Evernden
+7  A: 

You can also use .find(expression) if you already have a jquery object within which you wish to search.

In your example:

jQuery('td[class=bgoff]').each(function() {
    var td = jQuery(this);
    $(td).find( <selector to search within td> );
});
Joel Potter
A: 

From the jQuery source:

// HANDLE: $(expr, context)  
// (which is just equivalent to: $(context).find(expr)
Tom Viner