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

              
                <h3>Preventing event bubbling</h3>
<p>By using the pointer-events css property</p>
<button id="buttonOne">
  <i class="fas fa-times"></i> Icon with events
</button>
<p>Clicking the button will result in a event target of [object HTMLButtonElement] (the button itself)</p>
<p>But clicking the X icon will result in a event target of [object HTMLElement] (the icon element). This is because the event will <a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#event_bubbling_and_capture" target="_blank">bubble up </a>to the button</p>

<button id="buttonTwo">
  <i class="fas fa-check"></i> Icon with pointer-events none
</button>
<p>Because of 'pointer-events: none;' clicking the icon in this button will result in a event target of [object HTMLButtonElement] (the button) just like clicking the button would</p>
              
            
!

CSS

              
                body {
  display: grid;
  place-content: center;
  min-height: 100vh;
  gap: 1rem;
  margin: 0;
  padding: 0 2rem;
  background-color: #04142F;
  font-family: sans-serif;
  line-height: 1.5rem;
}

button {
  padding: 1rem 1.5rem;
  font-size: 1.4rem;
  background-color: #013BC2;
  border: solid 1px #efefef;
  border-radius: 0.5rem;
  color: #efefef;
}

/* Prevent event bubbling from nested elements inside this button */
#buttonTwo > * {
  pointer-events: none;
}


h3 {
  margin: 0;
  color: #efefef;
}
p {
  margin: 0 0 0.5rem 0;
  max-width: 50ch;
  color: #efefef;
}
p a {
  color: #efefef;
}
              
            
!

JS

              
                const buttonOne = document.querySelector('#buttonOne');

buttonOne.addEventListener('click', (e) => {
  alert(e.target)
});

const buttonTwo = document.querySelector('#buttonTwo');

buttonTwo.addEventListener('click', (e) => {
  alert(e.target)
});
              
            
!
999px

Console