fix bug with attribute setting.

also assume no attributes & children if none are provided.
This commit is contained in:
trans_soup 2023-07-16 15:01:34 +02:00
parent 416d31b1ad
commit 05cd4cb3c9

View file

@ -15,13 +15,13 @@ function json_as_html (json, state = new Map()) {
return json_as_html(json(state), state); return json_as_html(json(state), state);
} }
const [type, attributes, children] = json; const [type, attributes = [], children = []] = json;
const elem = document.createElement(type); const elem = document.createElement(type);
attributes.forEach(([key, value]) => attributes.forEach(([key, value]) => {
elem[key] = value); elem.setAttribute(key, value);
// elem.setAttribute(key, value)); });
const child_nodes = use_as_array(children).map(child => json_as_html(child, state)) const child_nodes = use_as_array(children).map(child => json_as_html(child, state))
child_nodes.forEach(child => elem.appendChild(child)); child_nodes.forEach(child => elem.appendChild(child));