How do a get buttons not to take the focus?

Mike Peat picture Mike Peat · Jun 11, 2009 · Viewed 24.6k times · Source

I want my (ExtJS) toolbar buttons not to grab the focus on the web page when they are clicked, but to do their "thing" while leaving the focus unchanged by the click. How do I do that?

Answer

real4x picture real4x · Jun 20, 2015

Cancelling the default behavior of onmousedown prevents an element from getting the focus:

// Prevent capturing focus by the button.
$('button').on('mousedown', 
    /** @param {!jQuery.Event} event */ 
    function(event) {
        event.preventDefault();
    }
);