Reputation: 10552
I am using the following jQuery to wrap each letter in my element in a span:
$('.num .stat').children().andSelf().contents().each(function() {
if(this.nodeType == 3) {
var $this = $(this);
$this.replaceWith($this.text().replace(/(\w)/g, '<span class="s-$&">$&</span>'));
}
});
I will be wrapping numbers using this. The problem I'm having is that when there is a comma in my number (e.g. 23,000) the comma is not getting wrapped.
Any idea how I can get the comma's wrapped in a <span>
also?
Thanks!
Upvotes: 2
Views: 254
Reputation: 145408
Comma is not in the subset of \w
. You may use .
in order to match all characters:
$this.text().replace(/(.)/g, '<span class="s-$&">$&</span>')
Upvotes: 3