I\'m trying to wrap each text character inside a
with a span tag. No problem there, it\'s just that I a
You can do this by using the following code:
$("div").children().andSelf().contents().each(function(){ if (this.nodeType == 3) { var $this = $(this); $this.replaceWith($this.text().replace(/(\w)/g, "$&")); } });
See test case on jsFiddle.