Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  145] [ 7]  / answers: 1 / hits: 7309  / 5 Years ago, fri, december 20, 2019, 12:00:00

I'm developing an script that using nice select :



<div class=nice-select form-control    tabindex=0><span class=current>تعداد حمام</span>
<ul class=list >
<li data-value=1 class=option selected focus>1 حمام</li>
<li data-value=2 class=option>2 حمام</li>
<li data-value=3 class=option>3 حمام</li>
<li data-value=4 class=option>4 حمام</li>
</ul>
</div>



I check the documention and it have just two method:



$('select').niceSelect('update');

$('select').niceSelect('destroy');



It didn't say how to get the selected value , i google it too but anyway i couldn't get the selected value and another point is that i have more than one nice select in one page



How can i handle it?



Edited:
Thanks @jorge-fuentes-gonzález and this is the snippet/fiddle , can you help to get the selected value?


More From » jquery

 Answers
3

You have incorrect HTML. As you can see in the documentation, you have to create a normal HTML <select>, like this:



<select id=myselect>
<option data-display=Select>Nothing</option>
<option value=1>Some option</option>
<option value=2>Another option</option>
<option value=3 disabled>A disabled option</option>
<option value=4>Potato</option>
</select>


Then pass to it the niceSelect plugin:



$(#myselect).niceSelect();


And you will be able to get the value using simple JavaScript over your <select> tag:



var selected = $(#myselect).val();


niceSelect plugin is simply a wrapper. Creates HTML over your <select> HTML, but your <select> HTML still exists on the page, but hidden, and you can continue working with it:



enter



BUT you need to use <select> tags, not <ul><li> tags. I don't know where you got your code, but documentation is your friend. I've updated your fiddle here: https://jsfiddle.net/o7a4dtwv/


[#5272] Tuesday, December 17, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pranavrorys

Total Points: 466
Total Questions: 87
Total Answers: 115

Location: Barbados
Member since Sun, Nov 27, 2022
2 Years ago
pranavrorys questions
Fri, May 27, 22, 00:00, 2 Years ago
Thu, Oct 28, 21, 00:00, 3 Years ago
Sat, May 30, 20, 00:00, 4 Years ago
Fri, Oct 11, 19, 00:00, 5 Years ago
;