Call a sequence of javascript statements

How do I execute the below js while running a test case?

function appendHtml(el, str) {

var div = document.createElement(‘div’);

div.innerHTML = str;

while (div.children.length > 0) {

el.appendChild(div.children\[0\]);

}

}

var html = ‘

Some Title
’;appendHtml(document.body, html);

Answer:
Can be written in a single line

WebUI.executeJavaScript(“function appendHtml(e,n){var d=document.createElement(‘div’);for(d.innerHTML=n;d.children.length>0;)e.prepend(d.children[0])};var html=’

’;appendHtml(document.body, html)”, null);