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

              
                
<h1 class="title">
  A pen to understand the order in which the events are fired ( mousedown, mouseup, click & blur ).
</h1>

<div class="text-group">
  <h2>1. The Order</h2>
  <p>
    mousedown --> mouseup --> click
  </p>
  <i>Try cicking the button to log the event order</i>
</div>
<hr>

<div class="text-group">
  <h2>2. Introducing the blur </h2>
  <p>
    Now when you add a blur event into the picture, it is actually fired before the mouseup event and after the mousedown event of the button.
  </p>
  <i> Focus the Textfield & then click the button.</i>
</div>
<hr>

<div class="text-group">
  <h2>3. Preventing the blur </h2>
  <p>
    If you want to prevent the blur event from being fired, you have to do so when you are inside the mousedown event, you can do so by invoking the method <code>preventDefault()</code> on the event.
  </p>
  <i> Click the checkbox, focus input & then click the button, the textfield never loses focus now.</i>
</div>
<hr>

<div class="controls">
  <input type="text" id="input" />
  <button id="btn">Click me !</button>
  <label>
    <input type="checkbox" class="prevent-blur" />
      Prevent Blur
  </label>
  <button id="clear-log"> &times; Clear Log </button>
</div>

<div class="log-results"></div>

<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
              
            
!

CSS

              
                html, body {
  font-family: 'Open Sans';
}

.text-group {
  margin: 10px 0;
  padding: 0;
  h2 {
    margin: 0;
  }
}

.log-results {
  height: 300px;
  border: 1px dotted black;
  margin: 10px 0;
  padding: 10px;
  overflow: scroll;
}
              
            
!

JS

              
                var $button = $( '#btn' ),
    $textfield = $( '#input' ),
    $res = $( '.log-results' ),
    $checkbox = $( '.prevent-blur' ),
    preventBlur = false;

function logEvt ( el, type ) {
  $res.append( el + ' ' + type + ' is fired. <br>' );
}

$( '#clear-log' ).on( 'click', function () {
  $res.empty();
});

$textfield.on( 'blur', function () {
  logEvt( 'input', 'blur' );
});

$checkbox.on( 'change', function () {
  preventBlur = $( this ).prop( 'checked' );
});

$button
  .on( 'click',  function() {
    logEvt( 'button', 'click' );
  })
  .on( 'mousedown', function ( e ) {
    logEvt( 'button', 'mousedown' );
    if ( preventBlur ) {
      e.preventDefault();
    }
  })
  .on( 'mouseup', function () {
    logEvt( 'button', 'mouseup' );
  })
  .on('focus', function () {
    logEvt('button', 'focus');
  });
              
            
!
999px

Console