wrap each char in except tags with jQuery

后端 未结 1 1605
一整个雨季
一整个雨季 2021-01-19 05:03

I\'m trying to wrap each text character inside a

with a span tag. No problem there, it\'s just that I a

相关标签:
1条回答
  • 2021-01-19 05:16

    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, "<span>$&</span>"));
        }
    });
    

    See test case on jsFiddle.

    0 讨论(0)
提交回复
热议问题