Open valtlai opened 6 years ago
This spec doesn’t seem contain an API to parse CSS selectors.
I would like to create a function that turns a CSS selector into a HTML element. For example,
const elem = buildElem('button[type=button]#foo.bar.baz:disabled');
would do this:
const elem = document.createElement('button'); elem.setAttribute('type', 'button'); elem.id = 'foo'; elem.classList.add('bar'); elem.classList.add('baz'); elem.disabled = true;
which produces:
<button type="button" id="foo" class="bar baz" disabled></button>
For now, I would use regexes (buggy, hard to maintain) or a JS library (too much code), but it would be very nice to have a native API for selector parsing.
This spec doesn’t seem contain an API to parse CSS selectors.
I would like to create a function that turns a CSS selector into a HTML element. For example,
would do this:
which produces:
For now, I would use regexes (buggy, hard to maintain) or a JS library (too much code), but it would be very nice to have a native API for selector parsing.