JSFiddle - React, Tailwind, and code Playground

by rjha999

HTML

Hit enter after entering fruit name:
<input id="fruit"></input>
<br>
                        <select id="unit" class="styled" name="unit">
                        
                        <option  class="apple" value="apple">apple</option>
                        <option  class="orange" value="orange">orange</option>
                    </select>

JavaScript

$(document).ready(function(){

$("#fruit").change(function(){
   var rj=$(this).val();
    
    var isValuePresent=$("#unit>."+rj+"");
    if(isValuePresent!=null)
    {
        $("#unit").find('option').removeAttr("selected");
        $("#unit>."+rj+"").attr("selected","selected");
    }
});
    
    })