Home » Jquery » javascript – select2 v4 dropdown change event not working-Exceptionshub

javascript – select2 v4 dropdown change event not working-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

please help me, select2 v4+ change event not working.
this is my code :

$(document).ready(function(){
  $("#asal").on("change", function(){
  var asallbl = $("#asal :selected").parent().attr("label");
  if(asallbl === "Singapore"){
    $("#tujuan").find("optgroup[label='Indonesia']").show();
    $("#tujuan").find("optgroup[label='Singapore']").hide();
    $("#tujuan").prop("selectedIndex", 0);
  }else{
    $("#tujuan").find("optgroup[label='Indonesia']").hide();
    $("#tujuan").find("optgroup[label='Singapore']").show();
    $("#tujuan").prop("selectedIndex", 0);
  }
  });
});
How to&Answer: