Modify ↓
Ticket #6723 (closed bug: duplicate)
:has fails in combination with :gt
| Reported by: | acdha | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | selector | Version: | 1.4.4rc |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Assuming a list like:
<ul><li></li><li></li><li></li></ul>
expressions like jQuery("ul:has(li:gt(1)") will fail to match anything.
I was going to write a test-case but there's a nice one here which I couldn't find referenced in the bug tracker: http://kruisit.nl/jquerybugs/?version=nightly
There is a workaround:
jQuery("ul").has("li:gt(1)")
or
jQuery("li:gt(1)").parent()
Change History
comment:2 Changed 3 years ago by rwaldron
- Priority set to low
- Status changed from new to open
- Version changed from 1.4.2 to 1.4.4rc
- Milestone 1.4.3 deleted
Confirmed; http://jsfiddle.net/rwaldron/CS8Bm/1/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Note for anyone else trying: the first workaround with .has() is not correct as it will match as long as there are more than the :gt() count elements anywhere on the entire page, not just under the selected <ul>. To get this to work reliably with jQuery 1.4.2 requires something like this:
jQuery("ul").each(function (i) { if ($(this).children("li").length > 10) { … } });