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


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <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