Skip to content

Instantly share code, notes, and snippets.

@thetallweeks
Created January 17, 2014 20:31
Show Gist options
  • Save thetallweeks/8480862 to your computer and use it in GitHub Desktop.
Save thetallweeks/8480862 to your computer and use it in GitHub Desktop.
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