Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

              
                <div class="wrapper">
  <h1>i<span>.js</span></h1>
    <h4>JS like you'd speak</h4>

<div id="js-output" class="output lorem">Output Area</div>


<button id="js-update">Update</button>
<button id="js-dblclick">dbclick me</button>
<button id="js-removeClass">remove Class</button>
<p>When the class is removed the border goes away. Yay.</p>
  <a href="https://github.com/kevingimbel/i.js" target="_blank">Github</a>
</div>
              
            
!

CSS

              
                @import "compass/css3";

* {
  margin:0;
  padding:0;  
  position:relative;
  @include box-sizing(border-box);
}

html, body {
  font:1em/1.2em Helvetica, Arial, sans-serife;
  color:#000;
}

.wrapper {
  width:100%;
  max-width:30em;
  margin:2.5em auto;
  padding:1.5em;
}

h1 {
  line-height:1.4em;
  font-family:Courier;
  
  span {font-size:.6em;}
}

.output {
  width:100%;
  height:auto;
  padding:1.5em;
  background:#ddd;
}

.lorem {
  border:1px solid red;
}

button {
  @include appearance(none);
  @include border-radius(3px);
  margin:1em;
  border:none;
  background:#2c3e50;
  color:#fff;
  padding:.5em 1em;
}
              
            
!

JS

              
                // The _match function is used to find out what kind of element we're dealing with.
// 
// If it gets a Tag name (e.g. "pre", "h1") it will see that var a and var b are null
// but c is defined (or not undefined) so it returns the element via getElementByTagNames
// Notice: it always returns the FIRST element via getElementsByTagName!
// If a is not null it will return a querySelector (in this case a class)
// If b is not null it will return an ID. 
//
// that's it. 
var _match = function(el) {
    a = document.querySelector("."+el);
    b = document.getElementById(el);
    c = document.getElementsByTagName(el);
    if(a != null) {
        return a;
    }
    if(b != null) {
        return b;
    }
    if(c != undefined) {
        return c[0];
    }
};
// the I Object holds all function and is named I because 
// the functions are build like sentences. 
// 
// For example: You may think "Man, I want a Classname" so
// you write I.WantA.classname("thename") - that's it.
var I = {
    WantA: {
        // returns the first tag on the page
        tag: function(tagname) {
            var tag = document.getElementsByTagName(tagname);
            return tag[0];
        },
        
        // returns an element with matching ID
        ID: function(id) {
            var id = document.getElementById(id);
            return id;
        },

        // returns an element with a matching class
        classname: function(c) {
            var classname = document.querySelector("."+c);
            return classname;
        }
    },

    WantTo: {
        // update the text of an element
        update: function(el,content) {
            _match(el).innerText = content;
        },

        // add a Class to an existing element.
        addClass: function(el,c) {
            _match(el).className += " " + c;
        },

        // function to remove a class. Taken from: http://stackoverflow.com/a/2155755/2777153
        removeClass: function(el, c) {
            var reg = new RegExp('(\\s|^)'+c+'(\\s|$)');
            elm = _match(el);
            elm.className = elm.className.replace(reg,'');
        },

        // add an event. Yay!
        addEvent: function(type,el,f) {
                _match(el).addEventListener(type,f);
        }
    }
};

var q1 = "OHMAGAWD!";
var q2 = "Fuck yeah it works!";

// "I want to add an Event, 
// if you click on the element with the ID js-removeClass 
// a FUNCTION triggers"
// that's the code in spoken words, below it is in I.js
I.WantTo.addEvent("click", "js-removeClass",function() {
  I.WantTo.removeClass("output","lorem");
});

I.WantTo.addEvent("click","js-update",function() {
  I.WantTo.update("js-output",q1);
});

I.WantTo.addEvent("dblclick","js-dblclick",function() {
  I.WantTo.update("js-output",q2);
});

              
            
!
999px

Console