Thin wrapper around Element.querySelector() that qualifies the returned value as an HTMLElement.
Element.querySelector()
HTMLElement
Root element to search within. Returns null when el is nullish.
null
el
CSS selector passed to Element.querySelector.
Element.querySelector
The first matching HTMLElement, or null if none is found or the match is not an HTMLElement (e.g. SVG elements).
const container = document.createElement("div");container.innerHTML = "<button>Save</button><svg><circle /></svg>";querySelector(container, "button"); // HTMLButtonElementquerySelector(container, "circle"); // null (non-HTMLElement)querySelector(null, "button"); // null Copy
const container = document.createElement("div");container.innerHTML = "<button>Save</button><svg><circle /></svg>";querySelector(container, "button"); // HTMLButtonElementquerySelector(container, "circle"); // null (non-HTMLElement)querySelector(null, "button"); // null
Thin wrapper around
Element.querySelector()that qualifies the returned value as anHTMLElement.