123

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.

            
              <button no-js on-click-set-attribute=".style-target style color:blue;font-weight:bold;">
 Set styles
</button>

<button no-js on-click-remove-attribute=".style-target style">
  Remove styles
</button>
<br>
<p class="style-target">
  Watch my style change!
</p>

<hr align=left width=200 />
<br/>

<button no-js on-click-add-class=".class-target arial-font">
  Add class
</button>

<button no-js on-click-remove-class=".class-target arial-font">
  Remove class
</button>

<button no-js on-click-toggle-class=".class-target arial-font">
  Toggle class
</button>
<br />
<p class="class-target">
  Watch my font change!
</p>

<hr align=left width=200 />
<br/>

<button no-js on-click-set-text=".text-target Behold my new text value!">Set text</button>
<br />
<p><div class="text-target">Watch my text change!</div></p>

<hr align=left width=200 />
<br/>

<label for="change-bgcolor-text">
  Focus on the textbox below to see its background color change, <br />
  then tab off of it to see the background color change back.
</label>
<p>
<input id="change-bgcolor-text" type="text"
  no-js on-focus-remove-class-self="no-focus" 
        on-focus-add-class-self="focus" 
        on-blur-remove-class-self="focus" 
        on-blur-add-class-self="no-focus" />
</p>

<br />
<hr />
<p style="text-align:left;">If you find this demo useful, please consider <a href="https://www.paypal.me/RobertGravelle/1" target="_blank">donating $1 dollar</a> (secure PayPal link) for a coffee or purchasing one of my songs from <a href="https://ax.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?term=rob%20gravelle" target="_blank">iTunes.com</a> or <a href="http://www.amazon.com/s/ref=ntt_srch_drd_B001ES9TTK?ie=UTF8&field-keywords=Rob%20Gravelle&index=digital-music&search-type=ss" target="_blank">Amazon.com</a> for only 0.99 cents each.</p>
<p style="text-align:left;">Rob uses and recommends <a href="http://www.mochahost.com/2425.html" target="_blank">MochaHost</a>, which provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!</p>


            
          
!
            
              .arial-font {
  font-family: Arial, Helvetica, sans-serif;
}

.focus {
  background-color: powderblue;
}

.no-focus {
  background-color: white;
}

input[type="text"] {
  width: 200px;
  border: solid black 1px;
}
            
          
!
            
              /*
* Signature:
*   on-[evtType]-[action]-[propertyType] = "target propertyName propertyValue"
*   on-[evtType]-[action]-[propertyType] = "target propertyValue"
*   on-[evtType]-[action]-[propertyType]-self = "propertyName propertyValue"
*
* Supported propertyTypes:
*   attribute:
*     on-[eventType]-add||set-attribute="[target] [attributeName] [attributeValue]"
*     on-[eventType]-remove-attribute="[target] [attributeName]"
*   class:
*     on-[eventType]-add-class="[target] [className]"
*     on-[eventType]-set-class="[target] [className]"
*     on-[eventType]-remove-class="[target] [className]"
*     on-[eventType]-toggle-class="[target] [className]"
*     on-[eventType]-switch-class="[target] [className]"
*   id:
*     on-[eventType]-add||set-id="[target] [idValue]"
*     on-[eventType]-remove-id="[target]"
*   dom:
*     on-[eventType]-remove-dom="[target]"
*   value:
*     on-[eventType]-set-value="[form input target] [value]"
*     on-[eventType]-reset-value="[form input target]"
*   text:
*     on-[eventType]-set-text="[target] [textValue]"
*
*/
(function() {
  function NoJS (dom) {
    this.js(dom)
  }

  NoJS.prototype.js = function (dom) {
    dom = dom || 'html';
    var this_ = this;
    var isSelf = false;
    document.querySelector(dom).querySelectorAll('[no-js]').forEach(function(el) {
      Object.keys(el.attributes).forEach(function(prop) {
        var attr = el.attributes[prop];

        // to enable support for single and double dashes.
        // note the order of condition checking is important.
        if (attr.name.indexOf('on--') === 0) {
          var doubleDash = true;
          console.warn('Deprecation warning: using double dashes "--" are deprecated. Use a single dash "-" instead.')
        } else if (attr.name.indexOf('on-') === 0) {
          var doubleDash = false;
        } else {
          return;
        }

        var signatureParts = attr.name.split(doubleDash ? '--' : '-');
        var paramValues = attr.value.split(' ');

        var eventType = signatureParts[1], action = signatureParts[2], propertyType = signatureParts[3];

        if (signatureParts.length === 5 && signatureParts[4] === 'self') {
          var target = el;
          isSelf = true;
        } else {
          var target = paramValues[0];
        }

        var propertyValue;
        if (action !== 'remove' || action !== 'reset') {
          var index = this_._getPropertyValueIndex(propertyType, isSelf)
          // join space containing values that might have been split.
          propertyValue = paramValues.splice(index).join(' ')
        }

        var options = {
          action: action,
          target: target,
          sourceElement: el,
          propertyType: propertyType,
          propertyValue: propertyValue,
          propertyName: propertyType === 'attribute' ? paramValues[1] : propertyType
        }

        el.addEventListener(eventType, function(e) {
          this_._handler(options);
        })
      })
    })
  }

  NoJS.prototype._handler = function (options) {
    var targets = typeof options.target === "string" ? document.querySelectorAll(options.target) : [options.target];
    targets.forEach(function(el) {
      if (options.propertyType === 'class') {
        if (options.action === 'set') {
          el.className = options.propertyValue
        } else if (options.action == 'switch') {
          el.classList.remove(options.propertyValue)
          options.sourceElement.classList.add(options.propertyValue)
        } else {
          el.classList[options.action](options.propertyValue)
        }
      }

      else if (options.propertyType === 'attribute' || options.propertyType === 'id') {
        if (options.action === 'remove') {
          el.removeAttribute(options.propertyName)
        } else if (options.action === 'add' || options.action == 'set') {
          el.setAttribute(options.propertyName, options.propertyValue);
        }
      }

      else if (options.propertyType === 'dom' && options.action === 'remove') {
        el.remove();
      }

      else if (options.propertyType === 'value') {
        if (options.action === 'set') {
          el.value = options.propertyValue;
        } else if (options.action === 'reset') {
          el.value = null;
        }
      }

      else if (options.propertyType === 'text' && options.action === 'set') {
        el.innerText = options.propertyValue;
      }
    })
  }

  NoJS.prototype._getPropertyValueIndex = function (propertyType, isSelf) {
    var index = propertyType === 'attribute' ? 2 : 1;
    return isSelf ? index - 1 : index;
  }

  document.addEventListener('DOMContentLoaded', function() {
    window.no = new NoJS();
  })
})()
            
          
!
999px
🕑 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.

Console