You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
450 B
28 lines
450 B
|
2 years ago
|
"use strict";
|
||
|
|
|
||
|
|
const isDOMElement = require("./isDOMElement.js");
|
||
|
|
/**
|
||
|
|
* Find a DOM element.
|
||
|
|
*
|
||
|
|
* @param {Node|string} element
|
||
|
|
* @returns {Node|null}
|
||
|
|
*/
|
||
|
|
|
||
|
|
|
||
|
|
function findDOMElement(element, context) {
|
||
|
|
if (context === void 0) {
|
||
|
|
context = document;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (typeof element === 'string') {
|
||
|
|
return context.querySelector(element);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isDOMElement(element)) {
|
||
|
|
return element;
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = findDOMElement;
|