jQuery: The Write Less, Do More JavaScript Library

Ticket #189 (closed bug: invalid)

Opened 2 years ago

Last modified 1 year ago

prev() does not work as expected

Reported by: ieure Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.0 Component: core
Version: 1.0 Keywords:
Cc: Needs:

Description

prev() is supposed to return the unique preceding siblings of the selected set, but it doesn't work correctly. It seems to check the tag and/or class name instead of comparing the actual nodes.

E.g.:

<div>
    <span>1</span>
    <span>2</span>
    <span>3</span>
    <span>4</span>
    <span>5</span>
</div>

If you now do:

$('div span').hover(function()
{
    $(this).prev();
});

The returned set only contains the span node immediately preceding the hovered element, not every span node preceding it.

This happens in 1.0.1, by the way, though that's not an option in this form.

Attachments

Change History

Changed 2 years ago by joern

The discription of prev() is somewhat irritating: It states that it returns a set of elements. But in the next sentence, it says: It only returns the immediately previous sibling, not all previous siblings. I'm not sure about the intentions behind this, and if there is an easy way to do "prevs()" to return all previous siblings, not only the immediate.

Changed 2 years ago by john

  • status changed from new to closed
  • resolution set to invalid

This is correct, .prev() only retreives the single element preceding the current element - there is currently no way to select all preceding elements, but it's something that's going to be added very soon.

Note: See TracTickets for help on using tickets.