Social Media Photo by Matheus Frade on Unsplash
Create an element from a query selector string.
// as function
const a = qs2el('a#home.special[data-page=home]');
// or as literal
const button = qs2el`button${'.primary'}[disabled]`;
The exported function also have an .escape(value)
to safely parse text that might contain [
or ]
chars.
const value = 'this [might] be an issue';
const div = qs2el`div[data-blob=${qs2el.escape(value)}]`;
div.dataset.blob === value; // true