Assuming html
is string of HTML, you can use:
Create a new HTMLElement
with createElement()
:
let el = document.createElement('div');`
Then add the html inside the div
by changing the innerHTML
property:
el.innerHTML = html;
At this point, you have your HTML wrapped inside div
tags.
Append the first child of the created element to the body
of the document to only append the inside of the div
:
document.querySelector('body').appendChild(el.firstChild)
Lastly, return the newly added element:
return el
So the final code is:
Sk.domOutput = function(html) {
let el = document.createElement('div');
el.innerHTML = html;
document.querySelector('body').appendChild(el.firstChild)
return el
};