css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <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>
            
          
!
            
              @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;
    }
  }
}
            
          
!
            
              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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console