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.

            
              <div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

<input value="hello" />
            
          
!
            
              div { width: 50px; height: 50px; display: inline-block; margin: 5px; border-radius: 20px; }

.colored { background: #EEE; }

.bordered { border: solid 2px #aaa; }

.red { background: #F00; }

body { text-align: center; }
            
          
!
            
              console.clear();

////////////////////////////////////////

(function(){
  
  // EACHER, a loop utility   
  // Loop each item of an object or Array or use `querySelectorAll` to find DOM elements and loop through them.
    
  function eacher(obj,callback,thisArg) {
    if (!(this instanceof eacher)) { return new eacher(obj,callback,thisArg); }
  
    // If obj is a string, find elements with `querySelectorAll`, otherwise wrap in array if single element.
    obj = ( typeof obj === 'string' ? document.querySelectorAll(obj) :
           obj instanceof Node || obj instanceof Window ? [obj] : obj );
    
    if ( (this.length = obj.length) > 0 ) { this.extend(obj); }
    
    return this.each(obj,callback,thisArg);
  }

  var arr = Array.prototype,
      fn = eacher.fn = eacher.prototype = {
        constructor: eacher, // Ensure that all instances tie back to eacher
        splice: arr.splice, // Give the appearance of an Array in dev tools,
        push: arr.push,
        indexOf: arr.indexOf
      };

  // The main loop function.
  // `return this` to ensure chainability.
  eacher.each = fn.each = fn.forEach = function(obj,callback,thisArg){

    // If only one or two arguments are provided, assume the target is this and first argument is the callback
    if ( !thisArg && typeof callback !== 'function' ) {
      if ( typeof obj !== 'function' ) { return this; }
      thisArg = callback;
      callback = obj;
      obj = this;
    }

    var length = obj.length,
        likeArray = ( length === 0 || ( length > 0 && (length - 1) in obj )),
        i = 0;

    if ( likeArray ) {
      for ( ; i < length; i++ ) {
        if ( callback.call( thisArg || obj[i], obj[ i ], i ) === false ) { break; }
      }
    } else {
      for ( i in obj ) {
        if ( callback.call( thisArg || obj[i], obj[ i ], i ) === false ) { break; }
      }
    }

    return this;
  };

  // Add methods to all eacher instances using eacher.fn.extend
  eacher.extend = fn.extend = function() {
    var a = arguments,
        target = a[0],
        length = a.length,
        i = 1,
        key;

    if ( length === 1 ) {
      target = this;
      i = 0;
    }

    for ( ; i < length; i++ ) {
      if ( !a[i] ) { continue; }
      for ( key in a[i] ) {
        if ( a[i].hasOwnProperty(key) ) { target[key] = a[i][key]; }
      }
    }

    return target;
  }
  
  // Expose eacher to window
  self.eacher = self.E = eacher;
}());

(function(){
  
  var classList = ("classList" in document.createElement("_"));
  
  function modifyClass(obj,act,c) {
    if ( !c ) { return obj; }
    var classes = c.split(/\s+/);
    return obj.each(function(){
      if ( classList ) {
        this.classList[act].apply(this.classList, classes);
      } else {
        eacher.each(classes,function(cl){
          this.className = ( 
            act === 'add' ? this.className + cl : 
            this.className.replace(cl, '')
          );
        });
      }
    });
  }
  
  /*    if (this.classList) {
                this.classList[act].apply(this, classes);
            } else if (act === 'add') {
                this.className += ' ' + c;
            } else {
                this.className = this.className.replace(c, '');
            }*/

  eacher.fn.extend({
    addClass: function(c){ return modifyClass(this,'add',c); },
    removeClass: function(c){ return modifyClass(this,'remove',c); },
    toggleClass: function(c, state){
      if ( state !== undefined ) { return modifyClass(this, state ? 'add' : 'remove' ,c); }
      return this.each(function(){
        if ( this.classList && this.classList.toggle ) { this.classList.toggle(c); }
        else { modifyClass(this,this.className.indexOf(c) >= 0 ? 'remove' : 'add',c); }
      });
    },
    hasClass: function(c){
      var check = false;
      if ( !c ) { return check; }
      this.each(function(){
        check = ( this.classList ? this.classList.contains(c) : new RegExp('(^|\s)' + c + '(\s|$)', 'gi').test(this.className) );
        return !check; // We only need one to be true, so break the loop if true.
      });
      return check;
    }
  });
  
})();

(function(){
  
  eacher.fn.extend({

    attr: function(attrName, value){
      if ( arguments.length === 1 ) { return this[0].getAttribute(attrName); }
      else if ( value === undefined ) { return this; }
      return this.each(function(){ this.setAttribute(attrName,value); });
    },

    removeAttr: function(attrName){
      return this.each(function(){ this.removeAttribute(attrName); });
    },

    data: function(){
      arguments[0] = 'data-' + arguments[0];
      return this.attr.apply(this,arguments); //this.attr('data-'+key,value);
    },

    removeData: function(){
      arguments[0] = 'data-' + arguments[0];
      return this.removeAttr.apply(this,arguments); //this.attr('data-'+key,value);
    },

    prop: function(propName, value){
      if ( arguments.length === 1 ) { return this[0][propName]; }
      return this.each(function(){ this[propName] = value; });
    },

    removeProp: function(propName) {
      return this.each(function(){ delete this[propName]; });
    },

    val: function(val){
      var args = ['value'];
      if ( val !== undefined ) args.push(val);
      return this.prop.apply(this,args);
    },

    html: function(content){
      if ( arguments.length === 0 ) { return this[0].innerHTML; }
      return this.each(function(){ this.innerHTML = content; });
    },

    text: function(content){
      if ( arguments.length === 0 ) { return this[0].textContent; }
      return this.each(function(){ this.textContent = content; });
    },

    empty: function(){ return this.html(''); },
    remove: function(){ return this.each(function(){ this.remove(); }); }

  });
  
})();

var divs = eacher('div',function(){ 
  this.classList.add('colored');
});

// Array-like functions
console.log(divs.indexOf(divs[1]));
divs.forEach(function(val,i){
  console.log(this, val,i);
},['thisValue']);

console.log(eacher('input').val());

// jQuery-like functions
divs
  .addClass('red bordered')
  .toggleClass('colored')
  .removeClass('red')
  .attr('aria-hidden',true);

eacher({ test: true, blah: false, me: [0,1,2] },function(i,e){ console.log(i,e); });

console.log(eacher.extend({ test: true },{ blah: false }));

console.log(divs,divs instanceof eacher);


/*
// Micro utility
function eacher(obj,callback) {
  // If selector is a string, find elements with `querySelectorAll`, otherwise wrap in array if single element.
  obj = ( typeof obj === 'string' ? document.querySelectorAll(obj) :
               obj instanceof Node ? [obj] : obj );

  for (var i = 0; i < obj.length; i++ ) {
    if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { break; }
  }

  return obj;
}
/**/

/* 

function eacher(obj,callback) {
  // If selector is a string, find elements with `querySelectorAll`, otherwise wrap in array if single element.
  obj = ( typeof obj === 'string' ? document.querySelectorAll(obj) :
               obj instanceof Node ? [obj] : obj );
  var len = obj.length,
      likeArray = ( len === 0 || ( len > 0 && (len - 1) in obj ) ),
      i = 0;

  if ( likeArray ) {
    for ( ; i < len; i++ ) {
      if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { break; }
    }
  } else {
    for (i in obj) {
      if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { break; }
    }
  }

  return obj;
}

*/

            
          
!
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