Bug Tracker

Modify

Ticket #395 (closed bug: duplicate)

Opened 7 years ago

Last modified 6 years ago

$(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

comment:1 Changed 7 years ago by brandon

  • Status changed from new to closed
  • Resolution set to duplicate

See #310

This is now fixed in SVN Rev: 585

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.