Hola:
Código:
<html>
<head>
<script>
function mensaje(elemento, dato) {
x = document.createTextNode(dato);
with(elemento.parentNode)
(lastChild == elemento) ? appendChild(x) : insertBefore(x, elemento.nextSibling);
}
</script>
</head>
<body>
<div onclick="mensaje(this, 'hola')" >pinchame</div>
</body>
</html>
Es lo que propone alvlin controlando que haya un nextSibling.
Saludos