Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 769
Mike Peat Avatar asked Jun 11 '09 16:06

Mike Peat


People also ask

How do I stop my button from focusing?

If you use the rule :focus { outline: none; } to remove outlines, the link or control will be focusable but with no indication of focus for keyboard users.

How do I get rid of focus on buttons on click?

To remove focus around the button outline:none property is used. Outline property: Outline is an element property which draws a line around element but outside the border. It does not take space from the width of an element like border.

How do I set focus button?

To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.


1 Answers

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();     } ); 
like image 76
real4x Avatar answered Sep 20 '22 13:09

real4x