Finding text node

前端 未结 8 1260
半阙折子戏
半阙折子戏 2021-01-03 08:14

Is there a clever jQuery selector for selecting a text node like this:

one two three
8条回答
  •  一生所求
    2021-01-03 08:54

    If it's not about the last word, but about the div's pure content try this:

    var chld=$('div').children().clone();
    $(div).children().remove();
    //now do what You want with the text, eg.
    $(div).html(''+$(div).text()+''); //or something like that :)
    $(div).prepend(chld); //This is a bottleneck, cause You have to know that 
              //all the text was after all the markup, but it refers to Your example.
    

提交回复
热议问题