javascriptbuttonextjsfocus

How do a get buttons not to take the focus?


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?


Solution

  • 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();
        }
    );