<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
span {
color: red;
}
</style>
</head>
<body>
<div class="somediv">
<a href="#">1</a><br/ >
<a href="#">2</a><br/ >
<a href="#">3</a><br/ >
<a href="#">4</a><br/ >
5<br/ >
6<br/ >
7<br/ >
8<br/ >
</div>
<script>
var div = document.querySelector('.somediv');
Array.prototype.forEach.call(div.childNodes, function(item) {
if(item.nodeType == 3 && item.data.match(/\S+/)) {
var span = document.createElement('span');
span.innerHTML = item.data;
item.parentNode.replaceChild(span, item);
}
});
</script>
</body>
</html>