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 comment:1
keywords: | → 1.7-discuss |
---|
Changed May 22, 2011 08:33PM UTC by 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. \ \ Rob → 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 |
---|
-1, This needs education, not new features.
Changed May 22, 2011 10:56PM UTC by 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 comment:4
-1, depth is the worst info you could use to select in the DOM.
Changed May 23, 2011 05:07AM UTC by comment:5
-1,
Changed May 23, 2011 05:14AM UTC by comment:6
component: | unfiled → selector |
---|---|
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 → 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 |
priority: | undecided → low |
@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 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 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 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 comment:10
status: | new → open |
---|
Changed May 24, 2011 10:22PM UTC by comment:11
-1, No new selectors
Changed June 03, 2011 02:10PM UTC by 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. \ \ Rob → 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 |
---|
-1, Plugin.
Changed June 04, 2011 10:15PM UTC by comment:13
-1
Changed June 05, 2011 10:29PM UTC by 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.\ \ Rob → 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 |
---|
-1, This scares me
Changed June 06, 2011 03:29PM UTC by 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. \ \ Rob → 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 |
---|
-1
Changed June 07, 2011 06:53PM UTC by comment:16
milestone: | 1.next → 1.7 |
---|---|
resolution: | → wontfix |
status: | open → closed |
Closing per 1.7 roadmap meeting resolution
Nominating ticket for 1.7 discussion.