I think we can write a simple virtual dom function like that. This isn't best but it should work :P
const domSource = [ { tagName: 'div', className: '' }, { tagName: 'p', children: [ { tagName: 'span' } ] } ] function virtualDom(element, domSource) { domSource.forEach(elData => { const { tagName } = elData const newElement = document.createElement(tagName) element.appendChild(newElement); const hasChild = elData.children && elData.children.length; if(hasChild) virtualDom(newElement, elData.children) }) } virtualDom(document.querySelector("#app"), domSource)
Hey! Itachi uchiha Have you tried to exceute it? 😃
I didn't. But I'm sure it will work for the first time.
When you run it secondly, probably it will create duplicate elements.
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.
I think we can write a simple virtual dom function like that. This isn't best but it should work :P
Hey! Itachi uchiha
Have you tried to exceute it?
😃
I didn't. But I'm sure it will work for the first time.
When you run it secondly, probably it will create duplicate elements.