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="movie">
  <button type="button" class="star"><span>&#9733;</span></button>
  <h1>The NeverEnding Story</h1>
  <img class="movie__image" src=",0,640,1000_AL_.jpg" alt="The NeverEnding Story">
              .movie {
  position: relative;
  cursor: pointer;
  background-color: magenta;
  width: 30%;
  padding: 12px;
  .movie__image {
    width: 80%;
    display: block;
    margin: 0 auto;

.star {
  font-size: 20px;
  font-weight: bold;
  border: 2px solid black;
  background-color: white;
  cursor: pointer;
** Ejemplo de dos elementos anidados
** con dos eventos del mismo tipo (click)
** Cuando ocurre el que se encuentra anidado
** evitamos que ocurra el de la madre
** El reto es conseguir que cuando
** se haga click en la estrella ocurra una cosa
** y cuando se haga click en el div '.movie'
** suceda otra
const movie = document.querySelector('.movie');
const movieStar = document.querySelector('.star');

function handleMovieClick(e) {
  const clickedElement =;
  ** Si el elemento sobre el que se ha hecho click
  ** esta dentro de una etiqueta '.star'
  ** o es una etiqueta '.star' 
  if(clickedElement.closest('.star')) {
    // no hacemos nada --> return false;
    return false;
  console.log('MOVIE CLICK EVENT: open modal with detail');

function handleMovieStarClick(e) {
  console.log('STAR CLICK EVENT: change star style');

movie.addEventListener('click', handleMovieClick);
movieStar.addEventListener('click', handleMovieStarClick);
🕑 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.