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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              .main
  .row
    .half
      button#addBtn ADD Item
      button#changeBtn Change Item Text
      - n = 1
      ul#list(data-num="3")
        while n <= 3
          li= `list-${n++}`
    .half
      b log
      pre#pre
            
          
!

CSS

            
              button
  display: inline-block
  line-height: 2em
  max-width: 230px
  width: 45%

pre
  border: 1px solid #ededed
  background: #eee
  padding: 1em
  
.main
  margin: 1em auto
  max-width: 960px

.row
  display: flex
  width: 100%
  
.half
  width: 50%
            
          
!

JS

            
              const d = document;
const list = d.getElementById('list');
const nodelist = list.querySelectorAll('li');
const collection = list.children;

function printText(text) {
  const pre = d.getElementById('pre');
  if(pre.textContent) {
    text += "\n----\n"
  }
  pre.textContent = text + pre.textContent;
}

function listNum() {
  const text = [
    `NodeList(${nodelist.length})`,
    `HTMLCollection(${collection.length})`,
  ];
  printText(text.join("\n"));
}

listNum();

const addBtn = d.getElementById('addBtn');
const changeBtn = d.getElementById('changeBtn');

addBtn.addEventListener('click', function(evt) {
  const n = list.dataset.num - 0 + 1;
  const li = d.createElement('li');
  li.textContent = `list-${n}`;
  list.dataset.num = n;
  list.appendChild(li);
  listNum();
});

changeBtn.addEventListener('click', function(evt) {
  const listNum = list.dataset.num - 0;
  const n = Math.floor(Math.random() * listNum);
  //const n = list.children.length - 1;
  const li = list.children[n];
  const editNum = li.dataset.change - 0 || 0
  li.dataset.change = editNum + 1;
  li.textContent = `list-${n + 1}-${editNum + 1}: ${Date.now()}`;
  
  const text = [nodelist, collection].map((arg, i) => {
    const name = i? 'HTMLCollection' : 'NodeList';
    if(arg[n]) {
      const data = arg[n];
      return `${data.textContent} (${name})`;
    } else {
      return `list-${n+1} is undefined (${name})`;
    }
  });
  printText(text.join("\n"));
});
            
          
!
999px

Console