jQuery: wrap every nth word in a span

后端 未结 2 1179
傲寒
傲寒 2020-12-18 13:52

Is it possible in jquery to wrap each nth word in a span

so lets say I have the html string

great Prices great Service

2条回答
  •  失恋的感觉
    2020-12-18 14:56

    You could do it by first getting the text of the

    element, then split the string to an array, cycle through the array in a for loop, and whenever your iterator i is even, add span tags to the current word. Then, just rebuild the string and insert it as the text property of your

    tag.

提交回复
热议问题