Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select specific text on page and remove it

Is is possible to select specific text string on the page directly without a id, class, etc...

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

Is it possible?

like image 334
user357034 Avatar asked Aug 16 '10 21:08

user357034


1 Answers

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.

like image 180
Martin Vseticka Avatar answered Nov 10 '22 09:11

Martin Vseticka