Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can jQuery selectors be applied to an element rather than the whole document?

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?

like image 450
Florin Avatar asked Mar 09 '09 01:03

Florin


People also ask

Which selector helps to select all elements of a document except?

The :not() selector selects all elements except the specified element. This is mostly used together with another selector to select everything except the specified element in a group (like in the example above).

How do jQuery selectors work?

jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.

Which of the following is correct about jQuery selector?

Q 1 - Which of the following is correct about jQuery selector? A - A jQuery Selector is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria.


2 Answers

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

like image 178
Scott Evernden Avatar answered Oct 07 '22 17:10

Scott Evernden


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> );
});
like image 32
Joel Avatar answered Oct 07 '22 17:10

Joel