开发者

Jquery: Selecting specific characters/copy..*real* content not DOM elements

开发者 https://www.devze.com 2023-01-04 04:54 出处:网络
I\'d like to be able to run a search for the copyright, reg and tm symbols that were pasted in along with copy fro开发者_JS百科m something like Word and replace them with the proper html encoding such

I'd like to be able to run a search for the copyright, reg and tm symbols that were pasted in along with copy fro开发者_JS百科m something like Word and replace them with the proper html encoding such as ®

So far, I can't find out how to say, Look in the entire document for " ' " and replace it with "&rsquo'"

The only methods that get near only select text in the first element.

Can you search for specific text that is actual content and not id/class?


How about using the .html() function?

$('#offending-element-containing-stuff').html(
    $('#offending-element-containing-stuff').html().replace(/good/g, 'bad')
);

This takes all the HTML inside the element with the id offending-element-containing-stuff, replaces the characters and writes it back.

May be very slow, though.

If you need to search the whole document, use $(document) instead of $('offending-element-containing-stuff) (twice).

EDIT: Notice that I replaced the search string by a regular expression with the modifier /g to replace all occurrences.

0

精彩评论

暂无评论...
验证码 换一张
取 消