$(\"div.date\")
.contents()
.filter(
function(){
return this.nodeType != 1;
})
.wrap(\"\");
I
I needed to give each word a specific id, so, being a newbie, I studied the previously published answers code. Starting from Brad Christie's and Daniel Tonon's code I used .addClass to achieve this result:
$('.mydiv').each(function(){
var words = $(this).text().split(/\s+/);
var total = words.length;
$(this).empty();
for (index = 0; index < total; index ++){
$(this).append($(" ").addClass("myclass_" + index).text(words[index]));
}
})
which outputs:
bla
bla
bla
starting from:
bla bla bla
It works perfectly for my needs. Maybe some expert programmers could tune up that better!