How to wrap each word of an element in a span tag?

前端 未结 8 1779
忘掉有多难
忘掉有多难 2020-12-01 07:05
$(\"div.date\")
    .contents()
    .filter(
        function(){
            return this.nodeType != 1; 
        })
    .wrap(\"\");

I

8条回答
  •  不思量自难忘°
    2020-12-01 07:24

    var $div = $('.words');
    var divWords = $div.text().split(/\s+/);
    $div.empty();
    $.each(divWords, function(i,w){
      $('').text(w).appendTo($div);
    });
    

    Then

    Why hello there, world!

    becomes

    Why hello there, World!

提交回复
热议问题