Created
January 17, 2014 20:31
-
-
Save thetallweeks/8480862 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getPrevious(n, className) { | |
var y = n.previousSibling; | |
// Check if previous node is an element node with a specific class | |
while (y.nodeType != 1 || !y.classList.contains(className)) { | |
// If not, move on to previous node | |
y = y.previousSibling; | |
} | |
return y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment