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.

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="buttons">
  <button onclick="addMovie()">Add</button>
  <button onclick="removeMovie()">Remove</button>
</div>
<table>
  <tbody id="movies">
    <tr>
      <th>Title</th>
      <th>Release</th>
      <th>Director</th>
    </tr>
    <tr>
      <td>Toy Story</td>
      <td>November 22, 1995</td>
      <td>John Lasseter</td>
    </tr>

    <tr>
      <td>A Bug's Life</td>
      <td>November 25, 1998</td>
      <td>John Lasseter</td>
    </tr>

    <tr>
      <td>Toy Story 2</td>
      <td>November 24, 1999</td>
      <td>John Lasseter</td>
    </tr>

    <tr>
      <td>Monsters, Inc.</td>
      <td>November 2, 2001</td>
      <td>Pete Docter</td>
    </tr>

    <tr>
      <td>Finding Nemo</td>
      <td>May 30, 2003</td>
      <td>Andrew Stanton</td>
    </tr>

    <tr>
      <td>The Incredibles</td>
      <td>November 5, 2004</td>
      <td>Brad Bird</td>
    </tr>

    <tr>
      <td>Cars</td>
      <td>June 9, 2006</td>
      <td>John Lasseter</td>
    </tr>
  </tbody>
</table>
              
            
!

CSS

              
                @mixin has-nth($expression, $element: '*') {
  &:nth-last-child(#{$expression}):first-child,
  &:nth-last-child(#{$expression}):first-child ~ #{$element} {
    @content;
  }
}


@mixin at-least($quantity, $element: '*') {
  @include has-nth('n + #{$quantity}', $element) {
    @content;
  }
}

table {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  text-align: left;
}

th, td {
  padding: .25em .5em
}

tr {
  &:first-child {
    border-bottom: 1px solid black;  
  }
  
  @include at-least(5) {
    &:nth-child(odd) {
      background: #ccc;
    }
  }
}
              
            
!

JS

              
                function addMovie() {
  var movies = [
  {
    'title': 'Toy Story',
    'release': 'November 22, 1995',
    'director': 'John Lasseter'
  },
  {
    'title': 'A Bugs Life',
    'release': 'November 25, 1998',
    'director': 'John Lasseter'
  },
  {
    'title': 'Toy Story 2',
    'release': 'November 24, 1999',
    'director': 'John Lasseter'
  },
  {
    'title': 'Monsters, Inc.',
    'release': 'November 2, 2001',
    'director': 'Pete Docter'
  },
  {
    'title': 'Finding Nemo',
    'release': 'May 30, 2003',
    'director': 'Andrew Stanton'
  },
  {
    'title': 'The Incredibles',
    'release': 'November 5, 2004',
    'director': 'Brad Bird'
  },
  {
    'title': 'Cars',
    'release': 'June 9, 2006',
    'director': 'John Lasseter'
  },
  {
    'title': 'Ratatouille',
    'release': 'June 29, 2007',
    'director': 'Brad Bird'
  },
  {
    'title': 'WALL-E',
    'release': 'June 27, 2008',
    'director': 'Andrew Stanton'
  },
  {
    'title': 'Up',
    'release': 'May 29, 2009',
    'director': 'Pete Docter'
  },
  {
    'title': 'Toy Story 3',
    'release': 'June 18, 2010  ',
    'director': 'Lee Unkrich'
  },

  {
    'title': 'Cars 2',
    'release': 'June 24, 2011',
    'director': 'John Lasseter'
  },

  {
    'title': 'Brave',
    'release': 'June 22, 2012',
    'director': 'Mark Andrews &amp; Brenda Chapman'
  },

  {
    'title': 'Monsters University',
    'release': 'June 21, 2013  ',
    'director': 'Dan Scanlon'
  },

  {
    'title': 'Inside Out',
    'release': 'June 19, 2015',
    'director': 'Pete Docter'
  },

  {
    'title': 'The Good Dinosaur',
    'release': 'November 25, 2015  ',
    'director': 'Peter Sohn'
  },

  {
    'title': 'Finding Dory',
    'release': 'June 17, 2016  ',
    'director': 'Andrew Stanton'
  },
];
  var table = document.getElementById('movies');
  var count = table.children.length - 1;
  var movie = movies[count % movies.length ];
  console.log(count);
  console.log(movies.length);
  
  
  var titleCell = document.createElement('td');
  titleCell.innerHTML = movie.title;
  
  var releaseCell = document.createElement('td');
  releaseCell.innerHTML = movie.release;
  
  var directorCell = document.createElement('td');
  directorCell.innerHTML = movie.director;
  
  var movieRow = document.createElement('tr');
  movieRow.appendChild(titleCell);
  movieRow.appendChild(releaseCell);
  movieRow.appendChild(directorCell);
  table.appendChild(movieRow);

}

function removeMovie() {
  var count = document.getElementById('movies').children.length;
  var lastItem = document.getElementById('movies').children[count - 1].remove();
}
              
            
!
999px

Console