Find text in element that is NOT wrapped in html tags and wrap it with

前端 未结 1 332
后悔当初
后悔当初 2021-01-13 19:44

Lorem Ipsum

TEXT THAT NEEDS TO BE WRAPPED
  • List Item 1
1条回答
  •  借酒劲吻你
    2021-01-13 20:33

    Use contents() and filter() to get text node

    $('.menu-content')
      .contents() // get all child node including text and comment 
      .filter(function() { // filter the text node which is not empty
        return this.nodeType === 3 && $.trim(this.textContent).length
      }).wrap('

    '); // wrap filtered element with p
    
    

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