Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For your project (creating a chrome extension to remove ads) you do not actually need to manipulate text, you need to manipulate HTML code, or more specificall: the DOM, the document object model that represents the HTML code in your browser. You can do this quite conveniently with jQuery.</p> <p>Here's how you would delete ALL li's containting DELETEME:</p> <pre><code>$('li:contains(DELETEME)').remove(); </code></pre> <p>here's a fiddle: <a href="http://jsfiddle.net/bjelline/RrCGw/" rel="nofollow">http://jsfiddle.net/bjelline/RrCGw/</a></p> <p>The best way to try this out is to open den developer tools in your browser and type the commands into the console, then you will see the effect immediately.</p> <p>For example: google for "learn javascript" - you'll probably see an ad. Look at the HTML source code to finde out that the id is inside a div with id "tads". Now open the console and type in</p> <pre><code>$('#tads').remove(); </code></pre> <p>And the ads will disappear.</p> <hr> <p>You specifically asked about manipulating text. When manipulating text it's a good idea to learn about regular expressions - not just for JavaScript, you can use them in many programming languages.</p> <p>If your whole text is stored in the variable string, you could do this:</p> <pre><code>string = string.replace(/.*DELETEME.*/, "XXXX"); </code></pre> <p>to replace the line with XXXX. Just use an empty string as a replacement to empty it completely:</p> <pre><code>string = string.replace(/.*DELETEME.*/, ""); </code></pre> <p>The ".*" stands for "any character, repeated as often as necessary", which matches the text before and after DELETEME. This regular expression only works on one line, so text on other lines is not changed.</p> <p>See <a href="http://jsfiddle.net/bjelline/Wc7ve/" rel="nofollow">http://jsfiddle.net/bjelline/Wc7ve/</a> for a working example.</p> <p>But, as stated above: this is not the right tool for your project.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload