开发者

select specific text on page and remove it

Is is possible to select specific text string on the page directly wit开发者_开发知识库hout a id, class, etc...

I have this text string "ERROR: AffiliateID invalid" that I would like to remove from the page.

Is it possible?


This should solve the problem imho:

document.body.innerHTML = document.body.innerHTML.replace( /ERROR: AffiliateID invalid/g, "");

The code replaces all occurences of the string with empty string.

EDIT: Use it only if you're 100 percent positive that it won't break your HTML in any way.

EDIT 2:

I don't know about a specific jQuery function for this. I found this tip:

1) http://johannburkard.de/blog/programming/javascript/6-quick-jquery-tips-text-manipulation-timers-and-elements.html

Remove a word with jQuery

The simple way – using regular expressions:

var el = $('#id'); el.html(el.html().replace(/word/ig, ""));

The example uses the same replace function as the version in pure javascript. The function comes from JavaScript 1.2 (the standard that is 10 years old and is implemented in all major browsers). So I guess there's no reason to use a function from jQuery.

2) There is a plugin for replacing text in specified HTML tags. Maybe it is worth trying.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜