jQuery - wrap all unwrapped text in p tags

前端 未结 5 467
醉梦人生
醉梦人生 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 02:35

    Try this :-

    Some text here which is not wrapped in tags

    Some more text which is fine

    Blah blah another good line

    JS

        $(function(){
        var $temp = $('
    '); $('div.container p').each(function(){ $(this).appendTo($temp); }); if($.trim( $('div.container').html() ).length){ var $pTag = $('

    ').html($('.container').html()); $('div.container').html($pTag); } $('div.container').append($temp.html()); }); ​

    ​Here is the working example :-

    http://jsfiddle.net/dhMSN/12

提交回复
热议问题