css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <h1>Find Random Words and Add Span Class</h1>
   <button class="on">Redact</button>
   <button class="off">Un-Redact</button>
<div class="wrapper">
<div id="post-1">
<p>Lorem    ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lobortis adipiscing felis sed    porttitor. Nunc gravida purus at imperdiet    volutpat. <a href="Curabitur ultricies erat mollis sapien semper adipiscing">Curabitur ultricies erat mollis sapien semper adipiscing</a>. Phasellus elementum nunc eget velit facilisis convallis. Vivamus pulvinar dapibus dui sed pharetra. Praesent mauris turpis, porttitor sed pretium ac, feugiat a nunc. Suspendisse interdum condimentum venenatis. Donec gravida dui sit amet erat laoreet, porttitor sollicitudin tortor condimentum. Integer at venenatis odio. Pellentesque suscipit tellus augue, at dignissim nisi mollis at. Vestibulum a dictum nunc.</p>
<div id="post-2">
<p>Aenean eget condimentum augue. Sed tincidunt placerat nisi eu ultrices. Quisque in urna at erat venenatis imperdiet. Fusce nunc mi, imperdiet sed porta a, ornare ut justo. < Quisque id odio neque. Mauris dapibus ligula tincidunt sollicitudin bibendum. Pellentesque hendrerit, < lorem non sollicitudin lobortis, elit leo volutpat enim, ac rhoncus orci erat quis dui. Aliquam sed laoreet risus, ut viverra lacus. Vivamus elit massa, porttitor sed nisl in, tincidunt facilisis mauris. Fusce pharetra, lorem ac lobortis dapibus, sapien justo sagittis neque, facilisis faucibus mi augue eu nulla. Fusce vel erat malesuada, commodo nibh ac, pretium lorem. Nulla rhoncus arcu eget volutpat lobortis. Integer semper tellus dui, id bibendum lectus aliquam vel. Vestibulum pulvinar, purus sit amet luctus mollis, ante magna dapibus nibh, in malesuada purus quam ac erat. Morbi hendrerit sodales neque quis blandit.</p>
              body { 
  font-family: sans-serif;
  width: 960px;

nav, h1 {
a {

button {
  cursor: pointer;
.redact { 
  color:#000000; !important

.off {
  background: #bf45bf;
    // set up a loop to run the function 10 times on click
    var i=0;
    while (i<10) {                    
         var data = $('.wrapper').text();
         var arr = data.replace(/[^a-z0-9\s]/gi, '').split(/\s+/);
         var word = arr[Math.floor(Math.random() * arr.length)];
         var fullword = ' '+word+' ';
         // get the text, split in to array, select random word, remove special characters, add spaces around the word to ensure we only find the full word (rather than 'a' inside another word)
         var regex = new RegExp('(?![^<>]*>) *('+fullword+ ')'); //Regular Expression to avoid editing html tags
         $('.wrapper').html($('.wrapper').html().replace(regex,'  <span class="redact">'+word+'</span>  '));
        // highlight word, replacing removed spaces

         i++; // increase loop variable
    } // end while

    $('.wrapper').find('span.redact').each(function(index) {
    var text = $(this).text();//get span content
    $(this).replaceWith(text);//replace all span with just content

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................