Created
March 15, 2010 17:19
-
-
Save StevenBlack/333065 to your computer and use it in GitHub Desktop.
:headerBelow and :headerAbove
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery custom selectors for headers above (lower <h> tag) or below (higher <h> tag) given an arbitrary level | |
(function( $ ) { | |
$.extend($.expr[':'],{ | |
// selects all the headers below the passed index. So 2 matches <h3>, <h4>, <h5>. | |
headerBelow: function( elem, i, match ) { | |
if ( /h\d/i.test( elem.nodeName ) ) { | |
var level= parseInt( match[ 3 ], 10 ) + 1, str = "h["+ level +"-5]", re = new RegExp( str, "i" ), ret ; | |
return re.test( elem.nodeName ); | |
} | |
return false; | |
}, | |
// selects all the headers above the passed index. So 3 matches <h1> and <h2>. | |
headerAbove: function( elem, i, match ) { | |
if ( /h\d/i.test( elem.nodeName ) ) { | |
var level= ( parseInt( match [ 3 ], 10 ) - 1 ) || 1, str = "h[1-"+ level +"]", re = new RegExp( str, "i" ) ; | |
return re.test( elem.nodeName ); | |
} | |
return false; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment