Skip to main content

Bug Tracker

Side navigation

#6362 closed enhancement (invalid)

Opened March 26, 2010 06:22PM UTC

Closed July 25, 2011 04:11PM UTC

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

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

Attachments (0)
Change History (14)

Changed November 12, 2010 02:40AM UTC by snover comment:1

milestone: 1.4.3

Resetting milestone to future.

Changed November 19, 2010 07:31AM UTC by snover comment:2

priority: → low
status: newopen

Changed April 16, 2011 11:19PM UTC by john comment:3

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.

Changed April 17, 2011 11:45PM UTC by john comment:4

component: misctraversing

Changed May 22, 2011 07:27PM UTC by john comment:5

keywords: → 1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 10:13PM UTC by rwaldron comment:6

_comment0: +1, This seems like "indexOf", but for jQuery selector result objects, in which case, I support a semantically named implementation1306103028758151
description: 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()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()

+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/

Changed May 22, 2011 11:59PM UTC by jaubourg comment:7

+1, Makes sense to me

Changed May 23, 2011 01:57AM UTC by ajpiano comment:8

description: 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()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()

+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.

Changed May 23, 2011 03:10AM UTC by timmywil comment:9

description: 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()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()

+1, why not

Changed May 23, 2011 09:30PM UTC by dmethvin comment:10

description: 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()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()

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

Changed June 03, 2011 01:28PM UTC by john comment:11

description: 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()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()

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

Changed June 06, 2011 03:42PM UTC by jzaefferer comment:12

+0

Changed July 12, 2011 02:50PM UTC by dmethvin comment:13

description: 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()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()
milestone: 1.next1.7
priority: lowblocker

Changed July 25, 2011 04:11PM UTC by john comment:14

resolution: → invalid
status: openclosed

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