Modify ↓
Ticket #395 (closed bug: duplicate)
$(E ~ F) fails if E is the first sibling
| Reported by: | anonymous | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | core | Version: | |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I am having a problem with the "element preceded by" syntax for $. Example:
$(document).ready(function() {
$("div ~ span").background("red");
});
<body> <div> this is a div </div>
<span> this is a span </span> </body>
This does not turn the <span> to red. If I use "+" instead of "~", then the <span> turns red. The relevant code (lines 1653-1655 in jquery.js, rev 557), says:
if ( s.n > 0 )
for ( var i = s.n; i < s.length; i++ )
r.push( s[i] );
I haven't tested this, but I would eliminate the s.n > 0 check and I would start the iteration at s.n+1:
for ( var i = s.n+1; i < s.length; i++ )
r.push( s[i] );
Change History
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.

See #310
This is now fixed in SVN Rev: 585