cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

              <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


Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.


Loading ..................