$(\"div.date\") .contents() .filter( function(){ return this.nodeType != 1; }) .wrap(\"\");
I
var $div = $('.words'); var divWords = $div.text().split(/\s+/); $div.empty(); $.each(divWords, function(i,w){ $('').text(w).appendTo($div); });
Then
Why hello there, world!
becomes
Why hello there, World!