Javascript find text on page

前端 未结 5 581
广开言路
广开言路 2021-01-14 22:13

I need to run a search and replace on HTML similar to the following... I need to have \"Find Next\" \"Replace\" and \"Replace All\" options.... the trick is that I need to r

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 22:21

    You can select all divs with class item that are children of the element with ID sheet like so:

    $('#sheet > div.item')
    

    and you can set the text of each div.item with .text():

    $('#sheet > div.item').text(function (i, oldText)
    {
        return oldText.replace('something', 'somethingElse');
    });
    

    Is that what you're looking for?

提交回复
热议问题