Skip to content

Instantly share code, notes, and snippets.

@StevenBlack
Created June 3, 2010 17:14
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 StevenBlack/424169 to your computer and use it in GitHub Desktop.
Save StevenBlack/424169 to your computer and use it in GitHub Desktop.
// Source: http://www.ferretarmy.com/2010/05/10/extending-jquery-selectors-between/
$.expr[':'].between = function(
objNode,
intStackIndex,
arrProperties,
arrNodeStack)
{
var args = arrProperties[3].split(",");
var startSelector = args[0];
var endSelector = args[1];
var startIndex = -1;
var endIndex = -1;
// Find the start and end indexes.
for (var index = 0; index < arrNodeStack.length; index++)
{
if ($(arrNodeStack[index]).is(startSelector) && startIndex < 0)
startIndex = index;
else if ($(arrNodeStack[index]).is(endSelector) && endIndex < 0)
endIndex = index;
}
if (startIndex >= 0 &&
endIndex > 0 &&
intStackIndex > startIndex &&
intStackIndex < endIndex)
return true;
else
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment