jQuery - wrap all unwrapped text in p tags

前端 未结 5 460
醉梦人生
醉梦人生 2020-12-02 02:21

I have a situation where the following code is getting written to my page.

Some text here which is not wrapped in tags

Some mor

5条回答
  •  情歌与酒
    2020-12-02 02:40

    jQuery is bad at handling text nodes, so you'll need to do some direct DOM manipulation on this. This also uses the "trim" function.. Its on jsfiddle.

    var d = $("div")[0];
    
    for(var i=0; i" + node.textContent + "");
    }
    

提交回复
热议问题