Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Mobile - Hide Dropdown Option

I have a drop down and I want to hide certain options, except when I use JQuery Mobiles enhancement version through data-native-menu="false", the option (Test 2) does not hide. Going further, I will need to also update these dynamically as the user selects each option.

http://jsfiddle.net/AzdaR/

<select data-mini="true" data-native-menu="true">
    <option>Test 1</option>
    <option style="display: none">Test 2</option>
    <option>Test 3</option>
</select>

<select data-mini="true" data-native-menu="false">
    <option>Test 1</option>
    <option style="display: none">Test 2</option>
    <option>Test 3</option>
</select>
like image 217
user2158259 Avatar asked Jul 01 '26 15:07

user2158259


1 Answers

When using custom select menus your select DOM is replaced with other DOM elements on the build process. So you can't hide option elements and expect that your custom select menu also hides them.

However you can disable the option using disabled="disabled".

<select data-mini="true" data-native-menu="false">
    <option>Test 1</option>
    <option disabled="disabled">Test 2</option>
    <option>Test 3</option>
</select>

See this working demo

like image 73
letiagoalves Avatar answered Jul 03 '26 07:07

letiagoalves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!