cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              
<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'>
            
          
!
            
              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;
}
            
          
!
            
              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' );
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console