I have a select2 dropdown for countries (multiselect). When user types keywords, it shows the related items in the menu. For e.g., if user types ind, the menu shows
The keypress event has been deprecated. You may want to use keydown instead.
keydown
$(document).ready(function() { $('#example').select2(); $(".select2-search__field").on("keydown", function(e) { if (e.keyCode == 13) { alert(); } }); });
Argentina Brazil China India Indonesia