Skip to main content

Bug Tracker

Side navigation

#9391 closed feature (wontfix)

Opened May 22, 2011 07:10PM UTC

Closed June 07, 2011 06:53PM UTC

:depth() Selector

Reported by: onerob@gmail.com Owned by:
Priority: low Milestone: 1.7
Component: selector Version: 1.6.1
Keywords: 1.7-discuss Cc:
Blocked by: Blocking:
Description

I'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM).

This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after:

$('table.someClass > td:depth(3)')

which would be easier than...

$('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)')

If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write:

$('table#someClass > td:depth(2) td')

I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer.

Thanks for reading.

Rob

Attachments (0)
Change History (16)

Changed May 22, 2011 07:27PM UTC by john comment:1

keywords: → 1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 08:33PM UTC by rwaldron comment:2

description: I'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM). \ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after: \ \ $('table.someClass > td:depth(3)') \ \ which would be easier than... \ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)') \ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write: \ \ $('table#someClass > td:depth(2) td') \ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer. \ \ Thanks for reading. \ \ RobI'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM).\ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after:\ \ $('table.someClass > td:depth(3)')\ \ which would be easier than...\ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)')\ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write:\ \ $('table#someClass > td:depth(2) td')\ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer.\ \ Thanks for reading.\ \ Rob

-1, This needs education, not new features.

Changed May 22, 2011 10:56PM UTC by onerob@gmail.com comment:3

Replying to [comment:2 rwaldron]:

-1, This needs education, not new features.

Although my second example is silly – $('table#someClass > td:depth(2) td') – the first is not, as there's no simple means of stopping all descendant matching elements from being returned AFAIK. Another solution, then, could be:

$('td td td:stop')

Where :stop prevents the DOM being traversed to a greater depth than the initial level of matched elements.

Changed May 23, 2011 01:03AM UTC by jaubourg comment:4

-1, depth is the worst info you could use to select in the DOM.

Changed May 23, 2011 05:07AM UTC by timmywil comment:5

-1,

Changed May 23, 2011 05:14AM UTC by rwaldron comment:6

component: unfiledselector
description: I'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM).\ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after:\ \ $('table.someClass > td:depth(3)')\ \ which would be easier than...\ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)')\ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write:\ \ $('table#someClass > td:depth(2) td')\ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer.\ \ Thanks for reading.\ \ RobI'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM). \ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after: \ \ $('table.someClass > td:depth(3)') \ \ which would be easier than... \ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)') \ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write: \ \ $('table#someClass > td:depth(2) td') \ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer. \ \ Thanks for reading. \ \ Rob
priority: undecidedlow

@rob, yes I understood that, but the proposal indicates a misunderstanding of how selectors work. The proposal seems to assume that selectors are evaluated from right-to-left, when they're actually evaluated left to right - which makes a huge difference in how your proposal is interpreted.

Changed May 23, 2011 12:46PM UTC by onerob@gmail.com comment:7

Are you saying that there's no way to make this efficient, or that the idea is conceptually incorrect? (Genuinely curious).

Changed May 23, 2011 05:03PM UTC by paul.irish comment:8

-1, the usecase for nested tables is clear, i agree.. one could also set a class on each of the tables and reduce the selector that way.

can't thing of strong use cases other than nested tables.. makes sense for an external plugin.

Changed May 23, 2011 07:54PM UTC by anonymous comment:9

I'm working with a CMS where I have no access to the code that generates the source, unfortunately, so I can't add the class names or IDs I'd like.

Changed May 24, 2011 12:28AM UTC by timmywil comment:10

status: newopen

Changed May 24, 2011 10:22PM UTC by dmethvin comment:11

-1, No new selectors

Changed June 03, 2011 02:10PM UTC by john comment:12

description: I'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM). \ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after: \ \ $('table.someClass > td:depth(3)') \ \ which would be easier than... \ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)') \ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write: \ \ $('table#someClass > td:depth(2) td') \ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer. \ \ Thanks for reading. \ \ RobI'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM).\ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after:\ \ $('table.someClass > td:depth(3)')\ \ which would be easier than...\ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)')\ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write:\ \ $('table#someClass > td:depth(2) td')\ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer.\ \ Thanks for reading.\ \ Rob

-1, Plugin.

Changed June 04, 2011 10:15PM UTC by addyosmani comment:13

-1

Changed June 05, 2011 10:29PM UTC by ajpiano comment:14

description: I'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM).\ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after:\ \ $('table.someClass > td:depth(3)')\ \ which would be easier than...\ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)')\ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write:\ \ $('table#someClass > td:depth(2) td')\ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer.\ \ Thanks for reading.\ \ RobI'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM). \ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after: \ \ $('table.someClass > td:depth(3)') \ \ which would be easier than... \ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)') \ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write: \ \ $('table#someClass > td:depth(2) td') \ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer. \ \ Thanks for reading. \ \ Rob

-1, This scares me

Changed June 06, 2011 03:29PM UTC by scottgonzalez comment:15

description: I'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM). \ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after: \ \ $('table.someClass > td:depth(3)') \ \ which would be easier than... \ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)') \ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write: \ \ $('table#someClass > td:depth(2) td') \ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer. \ \ Thanks for reading. \ \ RobI'd like to see what I'd call a 'depth' selector or filter. This would let me find an element(s), matching a selector, that was specifically the nth nested level of that element down from the current location (in fact, it would be very handy to be able to traverse both up and down the DOM).\ \ This would be useful when working with sites that output code that contains a great deal of nesting of divs, ULs or tables. As an example, here's something of the flavour of what I'm after:\ \ $('table.someClass > td:depth(3)')\ \ which would be easier than...\ \ $('table.someClass > tbody > tr > td > table > tbody > tr > td > div > table > tbody > tr > td)')\ \ If you wanted to select all TDs that were 3 levels down and any other descendant TDs, you would simply write:\ \ $('table#someClass > td:depth(2) td')\ \ I suppose the downside is that people might use it out of laziness when it may be far more optimal to write code that was just a little longer.\ \ Thanks for reading.\ \ Rob

-1

Changed June 07, 2011 06:53PM UTC by rwaldron comment:16

milestone: 1.next1.7
resolution: → wontfix
status: openclosed

Closing per 1.7 roadmap meeting resolution