JSFiddle - React, Tailwind, and code Playground

by dhana36

HTML

<select id="addbtype" name="addbtype" style="margin-bottom:0px;width:130px;">
    <option class='type_selected1' id='qtype_1'>restaurant</option>
    <option  id='qtype_2'>clothings</option>
    <option  id='qtype_8'>paints</option>
</select>

<button id="pickid">pickid</button>

JavaScript

$(document).ready(function(){
    qtid = ''
$('#addbtype').change(function(){
    
    $('#addbtype option').removeClass('type_selected1')
   var qtid = $(this).children(":selected").attr("id").split('_')[1]
 $(this).children(":selected").addClass('type_selected1')
});

$('#pickid').click(function(){
    
    
    alert($('.type_selected1').attr("id").split('_')[1])
});
    
    })