Finding text node

前端 未结 8 1342
半阙折子戏
半阙折子戏 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:49

    Is there a reason why you can't wrap three in some html element when you are generating the markup? It isn't really possible to grab some random word from the text and wrap it - unless you know it will always be the absolute last word in the div. If so you could do this to get the word:

    var txt = $(div).text();
    var txtArr = txt.split();
    var wordToWrap = txtArr[txtArr.length - 1];
    

提交回复
热议问题