Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there such thing as a relative jQuery selector?

I have a reference to a jquery object with the this variable. I am looking for a way of applying the child selector to the object.

I'm using $(this).find('table > tbody > tr > td'), but what I'm aiming for is something more like $('[Value of $(this) goes here somehow] > table > tbody > tr > td').

I realise that I can do $(this).children('table').children('tbody').children('tr').children('td'), but I was wondering if there was some syntactic sugar I could use here.

like image 560
Eric Avatar asked Aug 23 '10 10:08

Eric


People also ask

How many types of jQuery selectors are there?

So far we have covered only three standard jQuery Selectors.

What are the selectors of jQuery?

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.

Are jQuery selectors the same as CSS selectors?

In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.

Which is the fastest selector in jQuery?

ID and Element selector are the fastest selectors in jQuery.


1 Answers

You can start with a child selector (>) when using .find() as well, like this:

$(this).find('> table > tbody > tr > td')

It's an often overlooked use case, but it works just great for what you're after.

like image 95
Nick Craver Avatar answered Sep 25 '22 11:09

Nick Craver