I saw this:
$("div").children().andSelf().contents().each(function(){
if (this.nodeType == 3) {
var $this = $(this);
$this.replaceWith($this.text().replace(/(\w)/g, "<span>$&</span>"));
}
});
here: wrap each char in except tags with jQuery
Now i try to give each span a id, but they end up all having the same id. The index that get's logged to the console however are different.
$("#content").children().andSelf().contents().each(function(index){
console.log(index);
if (this.nodeType == 3) {
var $this = $(this);
$this.replaceWith($this.text().replace(/(\w)/g, "<span id="+index+">$&</span>"));
}
});