user1556571
user1556571

Reputation:

JQuery focus without entering key event shortcut

Using keymaster library for defining and dispatching keyboard shortcuts, I defined shortcut key / to focus input element.

key('/', function() {
    $(".topbar input").focus();
  });

The issue is that when the / key is pressed, the input is focused with / entered value. I want to get rid of that.

Upvotes: 1

Views: 217

Answers (2)

Sravan
Sravan

Reputation: 18647

Try this.

key('/', function(event) {
   $(".topbar input").focus();
   event.preventDefault();
});

Upvotes: 3

Tewdyn
Tewdyn

Reputation: 717

It gets focused because you tell it to do so.

Remove this line:

 $(".topbar input").focus();

Or give it a function so that you can do stuff when it gets focused

$(".topbar input").focus(function(){

});

Upvotes: 0

Related Questions