Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
02-17-2014, 09:23 AM #1
- Join Date
- Dec 2011
- Thanked 0 Times in 0 Posts
Find text pattern/string and remove it from HTML source?
Assume I have a HTML code similar to
and delete it form HTML source. Be aware that I don't want to delete "aaa" or "blahblah" or even the whole <ul>...</ul> element.
So I can NOT use e.g. a JS code like:
Is there another way to delete a certain text (pattern) from HTML source (maybe with the help of jQuery)?
02-17-2014, 10:10 AM #2
- Join Date
- May 2012
- Thanked 32 Times in 30 Posts
You can work with document.body.innerHTML to get or set the body content.
Then the problem is to replace any carriage return, linefeed or tabulations with a regular expression ([\n\r\t]* for one or more of this invisible characters).Code:var content=document.body.innerHTML; alert(content) newContent=content.replace(/[\n\r\t]*<br>[\n\r\t]*bbb[\n\r\t]*<br>[\n\r\t]*ccc/g,''); alert(newContent); document.body.innerHTML=newContent;
Last edited by 007julien; 02-17-2014 at 10:33 AM.
Users who have thanked 007julien for this post: