Bug Tracker

Opened 13 years ago

Closed 12 years ago

#6362 closed enhancement (invalid)

jQuery.index() and jQuery.indexIn()

Reported by: jablko Owned by:
Priority: blocker Milestone: 1.7
Component: traversing Version: 1.4.2
Keywords: 1.7-discuss Cc:
Blocked by: Blocking:

Description (last modified by dmethvin)

The semantics of jQuery.index() are backwards depending whether you pass an element or a selector as an argument, http://api.jquery.com/index/

I wish the semantics were consistent, so this example,

var $href = $('[href]', data);

var index = $href.index($href.filter('[href="' + location + '"]'));
  • could be reduced to,
var $href = $('[href]', data);

var index = $href.index('[href="' + location + '"]');

I wish the two backwards semantics had two different names, e.g. jQuery.index() and jQuery.indexIn(), analogous to jQuery.append() and jQuery.appendTo()

Change History (14)

comment:1 Changed 13 years ago by snover

Milestone: 1.4.3

Resetting milestone to future.

comment:2 Changed 13 years ago by snover

Priority: low
Status: newopen

comment:3 Changed 12 years ago by john

Milestone: 1.next

We should look at this for 1.7 - I'm not convinced that the old way of .index() working really makes sense for our API.

comment:4 Changed 12 years ago by john

Component: misctraversing

comment:5 Changed 12 years ago by john

Keywords: 1.7-discuss added

Nominating ticket for 1.7 discussion.

comment:6 Changed 12 years ago by Rick Waldron

Description: modified (diff)

+1, This seems like "indexOf", but for jQuery selector result objects, in which case, I support a semantically named implementation, perhaps similar to: http://jsfiddle.net/rwaldron/9R9kP/

Last edited 12 years ago by Rick Waldron (previous) (diff)

comment:7 Changed 12 years ago by jaubourg

+1, Makes sense to me

comment:8 Changed 12 years ago by ajpiano

Description: modified (diff)

+0, I thought we made it work like the OP requested for 1.4. I suppose that having better named methods as opposed to argument-type magic would be an improvement.

comment:9 Changed 12 years ago by Timmy Willison

Description: modified (diff)

+1, why not

comment:10 Changed 12 years ago by dmethvin

Description: modified (diff)

+0, Not clear on the specific proposal here ... are we breaking code?

comment:11 Changed 12 years ago by john

Description: modified (diff)

+1, I'm not sure about indexIn but we should definitely look to change the semantics of .index(String) to make it more useful.

comment:12 Changed 12 years ago by jzaefferer

+0

comment:13 Changed 12 years ago by dmethvin

Description: modified (diff)
Milestone: 1.next1.7
Priority: lowblocker

comment:14 Changed 12 years ago by john

Resolution: invalid
Status: openclosed

We really need a clear solution here, rather than an ambiguous "needs improvement" in order to be a blocker.

Note: See TracTickets for help on using tickets.