0
objb.on('focus', function() {
    some code
});

objb.on('keydown', function() {
    same code as above
});

To avoid the repeating I tried:

objb.on('focus, keydown', function() {
    some code
});

Doesn't work. Is it possible this way?

1 Answers1

5

Almost - when you want to use .on to listen for multiple events, separate the event names with a plain space, not a comma:

const objb = $('.objb');
objb.on('focus keydown', function() {
  console.log('listener running');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="objb"></textarea>
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320