b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
424 stars 47 forks source link

Value-free attributes? #181

Open pcarrier opened 3 days ago

pcarrier commented 3 days ago

Can't find a way to construct a node like <option selected> as opposed to <option selected="">. Is that an option I missed?

b-fuze commented 3 days ago

deno-dom will try to follow the HTML standard, and HTML attributes must always have a value even if it's empty. The parser (just like any browser HTML parser) will parse them as a shorthand for attributes with an empty string value. Setting them from the DOM API will always require a string value even if that value is an empty string because that is what the HTML DOM API requires.

pcarrier commented 3 days ago

Thanks! I would love access to the shorthand when serializing to HTML. It does turn out to be lacking from browsers too though.