Created
June 18, 2022 15:08
-
-
Save intrnl/d44a674c07b011c63ae87561786380be to your computer and use it in GitHub Desktop.
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
/** | |
* @param {HTMLElement} node | |
* @param {string} target | |
* @returns {?HTMLElement} | |
*/ | |
export function query (node, target) { | |
if (node.matches(`[x-target~='this.${target}']`)) { | |
return node; | |
} | |
return node.querySelector(`[x-target~='${node.localName}.${target}']`) || null; | |
} | |
/** | |
* @param {HTMLElement} node | |
* @param {string} target | |
* @returns {HTMLElement[]} | |
*/ | |
export function queryAll (node, target) { | |
const array = []; | |
const matches = node.querySelectorAll(`[x-targets~='${node.localName}.${target}']`); | |
if (node.matches(`[x-targets~='this.${target}']`)) { | |
array.push(node); | |
} | |
return array.concat(matches); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment