Sure, in that case it's just a question of convenience. But you can also build nested elements, so it´s a way to compose your page or parts of it :
let d, h, b, count = 0 d = div([ h = h1(`${count}`, { style: { color: "red" } }), b = button("CLICK") ]) b.onclick = () => h.innerText = ++count document.body.append(d)
By the way, CSS styles use a syntax, which is a bit different from JSON:
<p style="color:blue;font-size:46px;">
With your approach, people need to translate the style definition like this:
createElement("p",{style: {color:"blue";font-size:"46px;"})
As you need to process the styles anyway, would it not be better to use the usual syntax?
createElement("p",{style: "color:blue;font-size:46px;")
If you do not want to process the CSS manually, you can use this function:
function setStyle(el, css){ el.setAttribute('style', el.getAttribute('style') + ';' + css); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Sure, in that case it's just a question of convenience. But you can also build nested elements, so it´s a way to compose your page or parts of it :
By the way, CSS styles use a syntax, which is a bit different from JSON:
With your approach, people need to translate the style definition like this:
As you need to process the styles anyway, would it not be better to use the usual syntax?
If you do not want to process the CSS manually, you can use this function: