Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created March 11, 2012 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pifantastic/2017409 to your computer and use it in GitHub Desktop.
Save pifantastic/2017409 to your computer and use it in GitHub Desktop.
// Determine the position of an element within
// the matched set of elements
index: function( elem ) {
// No argument, return index in parent
if ( !elem ) {
return ( this[0] && this[0].parentNode ) ? this.prevAll().length : -1;
}
// index in selector
if ( typeof elem === "string" ) {
return jQuery.inArray( this[0], jQuery( elem ) );
}
// Locate the position of the desired element
return jQuery.inArray(
// If it receives a jQuery object, the first element is used
elem.jquery ? elem[0] : elem, this );
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment