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?
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?
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>