JSFiddle - React, Tailwind, and code Playground
HTML
<div class="dropDownType">
<div class="dropDownSelect"><span>Please Choose Yacht Type</span>
<div class="dropDownArrow"></div>
</div>
<div class="dropDownOption">
<div class='dropDownItem' data-vrijednost='-1' data-label='Any type'><i>*Any type</i>
</div>
<div class='dropDownItem' data-vrijednost='4' data-label='One'>One</div>
<div class='dropDownItem' data-vrijednost='9' data-label='Two'>Two</div>
<div class='dropDownItem' data-vrijednost='3' data-label='Three'>Three</div>
</div>
<select name="type" value="-1" style="display:none;">
<option value='-1'>Please select type</option>
<option value='4'>One</option>
<option value='9'>Two</option>
<option value='3'>Three</option>
</select>
</div>
CSS
.dropDownS .search-box-item, form .dropDownS input[type="text"], .dropDownS select, .dropDownS select option {
display: block;
margin: 5px;
padding: 3px;
padding-left: 10px;
padding-top: 10px;
width: 200px;
color: #FFF;
outline: none;
/*background */
background: #CCCC;
/* Old browsers */
/* .background*/
-webkit-box-shadow: inset 1px -1px 10px 1px #111;
box-shadow: inset 1px -1px 10px 1px #111;
-webkit-border-radius: 5px;
border-radius: 5px;
border: 2px solid #222;
text-shadow: 1px 1px 1px #000;
filter: dropshadow(color=#000, offx=1, offy=1);
}
.dropDownOption {
margin:5px;
background-color:#CCC;
width:210px;
margin-top:0px;
padding-left:-40px!important;
/*display:none;*/
position:absolute;
z-index:5000;
background: #CCC;
/* Old browsers */
}
.dropDownOption {
display:none;
width:240px;
position:absolute;
list-style:none;
}
.dropDownItem {
padding:10px;
cursor:pointer;
}
.dropDownItem:hover {
background-color:#333;
}
.dropDownArrow {
height:19px;
width:19px;
float:right;
cursor:pointer;
}
JavaScript
var dropAction = function (sta) {
sta.find('.dropDownSelect').find('span').text(sta.find("select option:selected").text());
sta.find('.dropDownSelect').on('click', function () {
//console.log($(sta).find('ul').html());
sta.find('.dropDownOption').slideDown(300);
});
sta.on('mouseleave', function () {
sta.find('.dropDownOption').slideUp(300);
});
sta.find('.dropDownOption').find('.dropDownItem').on('click', function () {
var index = $(this).index() + 1;
var myvalue = $(this).data("vrijednost");
sta.find('.dropDownSelect').find('span').text($(this).data('label'));
sta.find("select :nth-child(" + parseInt(index) + ")").siblings().removeAttr("selected");
sta.find("select :nth-child(" + parseInt(index) + ")").attr("selected", "selected");
sta.find("select").val(myvalue).change();
console.log(index);
console.log(myvalue);
console.log(sta.find("select").val());
sta.find('.dropDownOption').slideUp(300);
});
}
dropAction($('.dropDownType'));