Bug Tracker

Opened 11 years ago

Last modified 11 years ago

#3971 closed enhancement

.index() enhancement — at Initial Version

Reported by: ajpiano Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.1
Keywords: Cc:
Blocked by: Blocking:


It would be useful to be able to use the .index() method to find the index of the current element in a given set, rather than the current implementation (searching the current set for a given element), which forces the developer to do gyrations in order to find out a simple piece of info.

jQuery.fn.index = function(elem){

legacy implementation if ( typeof elem === 'object'){

return jQuery.inArray(

elem && elem.jquery ? elem[0] : elem

, this );

} return the index of the element in a new jQuery obj from selector, or by default, amongst its own siblings. return jQuery.inArray(this[0],

elem ? jQuery(elem) : this.parent().children() );


as per: http://groups.google.com/group/jquery-dev/browse_thread/thread/f5e07e2f81011d8b

Change History (2)

Changed 11 years ago by ajpiano

Attachment: index_enhancement.js added

Changed 11 years ago by paul.irish

Attachment: index.2009.03.05.patch added

a proper patch with testcases.

Note: See TracTickets for help on using tickets.