Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

From the jQuery source:

// HANDLE: $(expr, context)  
// (which is just equivalent to: $(context).find(expr)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top