-
-
Save otakustay/656ad559d110c3c868f8 to your computer and use it in GitHub Desktop.
How DOM element matches selectors
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
function findMatchingSelectors(dom) { | |
var isMatch = isSelectorMatch.bind(null, dom); | |
var result = []; | |
if (dom.id) { | |
var idSelectors = idSelectorMap[dom.id].filter(isMatch); | |
result.push.apply(result, idSelectors); | |
} | |
dom.classList.forEach(function (className) { | |
var classSelectors = classSelectorMap[className].filter(isMatch); | |
result.push.apply(result, classSelectors); | |
}); | |
var tagSelectors = tagSelectorMap[dom.nodeName].filter(isMatch); | |
result.push.apply(result, tagSelectors); | |
var remainingSelectors = remainingSelectorList.filter(isMatch); | |
result.push.apply(result, remainingSelectors); | |
return result; | |
} | |
function isSelectorMatch(dom, selector) { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment