<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
div.test {
border: 2px solid green;
display: inline;
padding: 0 5px;
text-align: center;
margin-right:30px;
}
</style>
</head>
<body>
<script>
function fn(str)
{
var container = document.createElement("div")
container.appendChild(document.createTextNode(str));
document.body.appendChild(container);
container.classList.add("test")
}
var arr = 'hello world hi javascript forum'.split(' ');
arr.forEach(function(it) {
fn(it);
});
</script>
</body>
</html>