Skip to content

Instantly share code, notes, and snippets.

@xsbee
Created April 3, 2022 04:27
Show Gist options
  • Save xsbee/a2915a348f2f55d9b02a70b9c247606b to your computer and use it in GitHub Desktop.
Save xsbee/a2915a348f2f55d9b02a70b9c247606b to your computer and use it in GitHub Desktop.
function selectIfPreviousAll(base, previous) {
var matches = [];
document.querySelectorAll(base).forEach(function(e) {
var siblings = e.parentElement.childNodes;
if(siblings.length < 2)
return;
var eIndex = Array.prototype.indexOf.call(siblings, e);
matches.push(siblings[eIndex - 1]);
});
return matches;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment