JSFiddle - React, Tailwind, and code Playground

by Felipe Kautzmann

HTML

<select id="dropdownId2">
    <option>Option 1</option>
    <option>Option 2</option>
</select>

JavaScript

var setLastSelected = function(c) {
   $(c).data('lastSelected', $(c).find("option:selected"));
};
        
$("#dropdownId2").click(function () {
   setLastSelected(this);
});

$("#dropdownId2").change(function(){        
      if(confirm("Remover?")) { 
          setLastSelected(this);
          return true; 
      }
      else {
         $(this).data('lastSelected').attr("selected", true);
         return false;
      }
});