JSFiddle - React, Tailwind, and code Playground
by Sumesh TG
HTML
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-nice-select/1.1.0/css/nice-select.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-nice-select/1.1.0/js/jquery.nice-select.js"></script>
<div class="frm-row">
<label>Brand</label>
<select class="wide" id="edu">
<option data-display="Select">Select Brand</option>
<option>Maruti Suzuki</option>
<option>Hyundai</option>
<option>Tata</option>
<option>Mahindra</option>
<option>Toyota</option>
</select>
</div>
<div class="frm-row">
<label>Model</label>
<select class="wide" id="edct">
<option data-display="Select">Select Model</option>
</select>
</div>
CSS
.nice-select {
border: solid 1px #CCC;
-webkit-tap-highlight-color: transparent;
clear: both;
border-radius:2px;
cursor: pointer;
display: block;
float: left;
font-family: inherit;
font-weight: normal;
line-height: 36px;
outline: none;
padding: 0 10px !Important;
position: relative;
text-align: left !important;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: auto;
margin-bottom: 18px
}
.nice-select:after {
border-bottom: 2px solid #999;
border-right: 2px solid #999;
content: '';
display: block;
height: 5px;
margin-top: -4px;
pointer-events: none;
position: absolute;
right: 12px;
top: 50%;
-webkit-transform-origin: 66% 66%;
-ms-transform-origin: 66% 66%;
transform-origin: 66% 66%;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
width: 5px; }
.nice-select.open:after {
-webkit-transform: rotate(-135deg);
-ms-transform: rotate(-135deg);
transform: rotate(-135deg); }
.nice-select.open {
border:1px solid #ffc107
}
.nice-select.open .list {
border:1px solid #ffc107;
opacity: 1;
pointer-events: auto;
-webkit-transform: scale(1) translateY(0);
-ms-transform: scale(1) translateY(0);
transform: scale(1) translateY(0); }
.nice-select.disabled:after {
border-color: #cccccc; }
.nice-select.wide {
width: 100%; }
.nice-select.wide .list {
left: 0 !important;
right: 0 !important; }
.nice-select.right {
float: right; }
.nice-select.right .list {
left: auto;
right: 0; }
.nice-select.small {
font-size: 12px;
height: 36px;
line-height: 34px; }
.nice-select.small:after {
...
JavaScript
$(document).ready(function () {
$('select').niceSelect();
});
var eduBak = {};
eduBak['Maruti Suzuki'] = ['Delhi', 'Mumbai', 'Chennai', 'Kolkata', 'Bangalore', 'Hyderabade', 'Pune'];
eduBak['Hyundai'] = ['Alabama', 'Alaska', 'Arizona'];
eduBak['Tata'] = ['England', 'Northrn Ireland', 'Scotland', 'Wales', 'other'];
eduBak['Mahindra'] = ['Alberta ', 'Brirish Columbia', 'Manitoba', 'others'];
eduBak['Toyota'] = ['Singapore', 'others'];
eduBak['Others'] = ['Others']
$('#edu').on('change', function() {
var edu = document.getElementById("edu");
var model = document.getElementById("edct");
var educ = edu.value;
while (model.options.length) {
model.remove(0);
}
var ed = eduBak[educ];
if (ed) {
var i;
for (i = 0; i < ed.length; i++) {
var e = new Option(ed[i], ed[i]);
model.options.add(e);
}
$('select').niceSelect('update');
}
});