Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                button(data-click-on) click 1 event
button(data-click-on) click 2 event
button(data-click-off) click off

p.log-sample
  | attribute value: 
  span.log
  
.test.set-active bla
.wrapper
  .test1xxx test1
  .test2 test2
  .test test2

- for (var i=0; i<1000; i++ )
  .test toto-#{i}
  
.test.set-active bla
.wrapper
  .test3 test3
  .test test3

              
            
!

CSS

              
                .test {
  &.active {
    color: red;
  }
  &.bold {
    font-weight: bold;
  }
}

              
            
!

JS

              
                ;(function(name, definition) {
  if (typeof module !== 'undefined') module.exports = definition();
  else if (typeof define === 'function' && typeof define.amd === 'object') define(definition);
  else this[name] = definition();
}('uuSelect', function() {

  'use strict';

  function loop(array, callback, scope) {
    for (var i = 0, len = array.length; i < len; i++) {
      callback.call(scope, i, array[i]);
    }
  }

  var __ = window.__ = function(selector, context) {
    return new __.fn(selector, context);
  };

  __.fn = function(selector, context) {
    var that    = this,
        context = document.querySelectorAll(context || 'body'),
        nodes;
    
    that.length = 0;

    // loop through contexts
    loop(context, function(index, value){
      nodes = value.querySelectorAll(selector || 'body');
      // loop through elements
      loop(nodes, function(index, value){
        that[that.length] = value;
        that.length++;
      });
    });

    return that;
  };

  __.fn.prototype = {
    // classList.add()
    addClass: function(string) {
      if (typeof string === 'undefined') return this;

      var names = string.split(' '),
          that  = this;

      loop(names, function(index, value){
        loop(that, function(index, value){
          value.classList.add(this);
        }, value);
      });
      return this;
    },

    // classList.remove()
    removeClass: function(string) {
      if (typeof string === 'undefined') return this;

      var names = string.split(' '),
          that  = this;

      loop(names, function(index, value){
        loop(that, function(index, value){
          value.classList.remove(this);
        }, value);
      });
      return this;
    },

    // classList.toggle()
    toggleClass: function(string) {
      if (typeof string === 'undefined') return this;

      var names = string.split(' '),
          that  = this;

      loop(names, function(index, value){
        loop(that, function(index, value){
          value.classList.toggle(this);
        }, value);
      });
      return this;
    },

    // classList.contains()
    hasClass: function(string) {
      if (typeof string === 'undefined') return false;

      for (var i = 0, len = this.length; i < len; i++) {
        if (this[i].classList.contains(string)) {
          return true;
        }
      }
      return false;
    },

    // getAttribute() | setAttribute()
    attr: function(property, setValue) {
      if (typeof property === 'undefined') return this;

      // getAttribute
      if (typeof property === 'string' && typeof setValue === 'undefined') {
        return that[0].getAttribute(property);
      }

      // setAttribute
      // ... multiple attributes
      if (typeof property === 'object') {
        for (var prop in property) {
          if (!property.hasOwnProperty(prop)) continue;

          loop(this, function(index, value){
            value.setAttribute(prop, property[prop]);
          });
        }
        return this;
      }

      // ... single attribute
      if (typeof property === 'string') {
        loop(this, function(index, value){
          value.setAttribute(property, setValue);
        });
      }
      return this;
    },

    // removeAttribute()
    removeAttr: function(string) {
      if (typeof string === 'undefined') return this;

      var names = string.split(' '),
          that  = this;

      loop(names, function(index, value){
        loop(that, function(index, value){
          value.removeAttribute(this);
        }, value);
      });
      return this;
    },

    // style
    css: function(property, setValue) {
      if (typeof property === 'undefined') return this;
      
      // getComputedStyle(). getPropertyValue()
      if (typeof property === 'string' && typeof setValue === 'undefined') {
        return getComputedStyle(this[0], null). getPropertyValue(property);
      }

      // style
      // ... multiple properties
      if (typeof property === 'object') {
        for (var prop in property) {
          if (!property.hasOwnProperty(prop)) continue;
          loop(this, function(index, value){
            value.style[prop] = property[prop];
          });
        }
        return this;
      }

      // ... single property
      if (typeof property === 'string') {
        loop(this, function(index, value){
          value.style[property] = setValue;
        });
      }
      return this;
    },
    
    // events manager
    on: function(event, listener, useCapture) {
      var useCapture = useCapture || false;

      loop(this, function(index, value){
        value.addEventListener(event, listener, useCapture);
      });
    },
    
    // events manager
    off: function(event, listener) {
      loop(this, function(index, value){
        value.removeEventListener(event, listener);
      });
    }
  };

  return __;
}));

function toto() { console.log('toto'); }
function toto2() { console.log('toto2'); }

function off() {
  console.log('off');
  __('[data-click-on]').off('click', toto2);
}

__('[data-click-on]').on('click', toto);
__('[data-click-on]').on('click', toto2);

__('[data-click-off]').on('click', off);



// TESTING
// -------
// You can still use vanilla JS if you need/want
// ... querySelector like
//__('.test')[0].classList.add("native");

// ... querySeletorAll like
/*for (var z = 0, len = __('.test').length; z < len; z++) {
  __('.test')[z].classList.add("loopnative");
}*/


// c-lector perf
console.time('timer');
  __('.test')
    .addClass('active bold toto')
    .removeClass('toto')
    .toggleClass('active')
    .attr('aria-label', 'test')
    .attr({
      'data-test': 'test',
      'data-bla': 'bla'
    })
    .removeAttr('data-test');

  // selector with context
  __('.test', '.wrapper').addClass('active');

  // hasClass
  if (__('.test').hasClass('xxx')) { // return true in this example
    __('.log-sample').css({
      'background-color': '#000',
      'color': '#fff'
    });
  }

  __('.test.active').css({
    'background-color': 'yellow',
    'font-size': '20px'
  });

  var log = __('.test.set-active')[0].innerHTML;
  __('.log')[0].innerHTML = log;
console.timeEnd('timer');


// jQuery perf
/*console.time('timer2');
  $('.test')
    .addClass('active bold toto')
    .removeClass('toto')
    .toggleClass('active')
    .attr('aria-label', 'test')
    .attr({
      'data-test': 'test',
      'data-bla': 'bla'
    })
    .removeAttr('data-test');

  // selector with context
  $('.test', '.wrapper').addClass('active');

  // hasClass
  if ($('.test').hasClass('xxx')) { // return true in this example
    $('.log-sample').css({
      'background-color': '#000',
      'color': '#fff'
    });
  }

  $('.test.active').css({
    'background-color': 'yellow',
    'font-size': '20px'
  });

  var log = $('.test.set-active').html();
  $('.log').html(log);
console.timeEnd('timer2');*/

              
            
!
999px

Console