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

Auto Save

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

              
                <section>
  <ul id="parent-ul-1">
    <li id="li-1" class="my-class">Item 1</li>
    <li id="li-2" class="my-class">Item 2</li>
    <li id="li-3" class="my-class">Item 3</li>
  </ul>
  <p id="display-msg-1"><p>
</section>

<section>
  <ul id="parent-ul-2">
    <li id="li-4" class="my-class">Item 4</li>
    <li id="li-5" class="my-class">Item 5</li>
    <li id="li-6" class="my-class">Item 6</li>
  </ul>
  <p id="display-msg-2"><p>
</section>

<section>
  <ul id="parent-ul-3">
    <li id="li-7" class="my-class">Item 7</li>
    <li id="li-8" class="my-class">Item 8</li>
    <li id="li-9" class="my-class">Item 9</li>
  </ul>
  <p id="display-msg-3"><p>
</section>

<section>
  <button id="unbind" type="button">Unbind Column 3</button>
  <button id="bind" type="button">Bind Column 3</button>
  <p id="display-msg-4"><p>
</section>
              
            
!

CSS

              
                $pri: #888;
$pri-light: lighten($pri, 20%);
$pri-dark: darken($pri, 20%);
$pri-dark-x: darken($pri, 30%);
* { box-sizing: border-box; }
body {
  font-family: arial;
  margin: 2em 1em;
  background: #222;
}
@keyframes play {
   0% { left: 0; }
   50% { left: 20px; }
   100% { left: 0;}
}
.moveMe {
  animation: play .8s;
  position: relative;
  margin: 0;
}
section {
  width: 25%;
  float: left;
  padding-right: 1%;
  }
ul {
  width: 100%;
  color: $pri-light;
  li {
    background-color: $pri-dark-x;
    border-bottom: 2px solid $pri-light;
    padding: 1em;
    list-style-type: none;
    cursor: pointer;
  }
 }
p {
  padding: 1em 0 0 0;
  color: #fff;
  font-size: 1em;
}
button {
  width: 100%;
  display: block;
  border: 0;
  background-color: $pri-dark;
  padding: .5em 1em;
  margin-bottom: 1em;
  font-size: 1em;
  color: $pri-light;
  border: 5px solid  $pri-light;
  &:hover { background-color: $pri-dark-x; }
  &:active { 
    box-shadow: inset 0 0 5px $pri-dark-x;
    background-color: $pri-dark-x; }
  &:focus { outline: 0; }
}
              
            
!

JS

              
                
// Event delegation is useful in that you only place the event listener on the parent to capture the bubbled event - imagine a table of 1000 rows. The callback function lets you handle it in any way.

var dm1 = document.getElementById("display-msg-1");
document.getElementById("parent-ul-1").addEventListener("click", function(e) {
  if(e.target) {
    var msg = "Clicked on: " + e.target.firstChild.nodeValue;
    // You could capture any attribute of this clicked element
    // "ID:" + e.target.id or "Class:" + e.target.className
    addRemoveClass(dm1, msg);
  }
});
function addRemoveClass(c, msg) {
  c.innerHTML = msg;
  c.classList.remove("moveMe");
  c.offsetWidth = c.offsetWidth;
  c.classList.add("moveMe");
}
// And with jQuery .delegate
$("#parent-ul-2").delegate( "li", "click", function() {
  var dm2 = $("#display-msg-2");
  var msg = dm2.text( "Clicked on: " + $(this).text());
  jq_addRemoveClass(dm2, msg);
});
// For .on just reverse the event and target
$("#parent-ul-3").on("click", "li", function() {
  var dm3 = $("#display-msg-3");
  var msg = dm3.text( "Clicked on: " + $(this).text());
  jq_addRemoveClass(dm3, msg);
});
function jq_addRemoveClass(c, msg) {
  c.removeClass("moveMe");
  c.outerWidth(true);
  c.addClass("moveMe");
}
// .off - removes both .delegate and .on
$( "#unbind" ).click(function() {
  $( "#parent-ul-3" )
    .off( "click", "li")
    .find( "#display-msg-4" )
    $("#display-msg-4" ).text("Removed .on from C3");
});
$("#bind").click(function() {
  // Real world, I'd abstract the sect 3 declaration into it's own function
    $("#parent-ul-3").on("click", "li", function() {
      
      var dm3 = $("#display-msg-3");
      var msg = dm3.text( "Clicked on: " + $(this).text());
      jq_addRemoveClass(dm3, msg);
    });
  $("#display-msg-4").text("Added .on to C3");
})
              
            
!
999px

Console