jruiz jruiz - 6 months ago 21
Javascript Question

I can't capture enter key in select2

I am using select2, and I need to capture the enter key, but I can't.

I used:

$(document).on('keydown', '.select2-input', function (ev) {

if (ev.which == 13) {
alert('press enter')

if (ev.which == 9) {
alert('press tab')

I can capture all the keys but for the enter.

Can someone help me?

Answer Source

Try this out:

$('select2-search-field > input.select2-input').on('keyup', function(e) {
   if(e.keyCode === 13) 
      alert('enter key event');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download