I have always had the assumption that onblur fires before onclick, but I just wanted to confirm it before things started unexpectedly breaking on me.

The onblur event fires on the original object before the onfocus or onclick event fires on the object that is receiving focus. Where applicable, the onblur event fires after the onchange event.


With IE covered, a quick check of a local script in Safari and Firefox proves this to be the case. A script such as the one below will work as expected:

var g_ID = 0;// called onclick
function clicked(id) {
    g_ID = id;
}// called onblur
function edited(val) {
    updateRecord(val, g_ID);

If we can look past the use of a global variable (I know, I know), the code shows that global ID is kept in tact, and will update correctly. So if object 1 has focus, and then object 2 is clicked, the record for object 1 will be updated and then the new ID will be set to that of object 2. Good to know.

HTML Form Builder
Ryan Campbell

onblur Before onclick by Ryan Campbell

This entry was posted 3 years ago and was filed under Notebooks.
Comments are currently closed.


  1. Arjan Eising · 3 years ago

    I never thought about this before, but when do you use it? I don’t even use the blur event handler, but more the :focus pseudo-selector from CSS.

  2. Andy Kant · 3 years ago

    @Arjan JavaScript events can be used for more than to define styles. :-P

    The blur event is actually pretty useful when it comes to client-side scripting, such as attaching dynamic data validation routines to textboxes.