I do not want the dropdown default selected option to display separately but why is this happening.
Is there an option to skip the jquery setting for a particular dropdown? Like using some function like preventDefault ?
Please refer the below url.
[1]: https://jsfiddle.net/ufLr0wo2/
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.5.0-rc1/jquery.mobile-1.5.0-rc1.min.js"></script>
</head>
<body>
<div class="">
<form>
<select>
<option value="0">item 0</option>
<option>item 1</option>
<option>item 2</option>
</select>
</form>
</div>
</body>
</html>
2
Answers
If you’re using the "nice-select" library to enhance your dropdown menus, and you want to prevent the default selected option from displaying separately, you can achieve this by configuring the library’s options or by customizing its behavior.
The "nice-select" library enhances the appearance and functionality of native HTML select elements. By default, it displays the selected option separately to provide a better user experience.
To prevent the default selected option from displaying separately, you may need to customize the library’s CSS or JavaScript.
Here’s how you can do it:
"nice-select" library to hide the selected option. You can do this
by targeting the .nice-select class and modifying its styles to hide
the selected option display.
"nice-select" library using its JavaScript API. You may need to dive
into the library’s source code to find the appropriate function or
option to achieve this. Look for functions or options related to
displaying the selected option, and see if you can customize or
disable them.
Here’s your code with a basic example of how you might use "nice-select" and apply CSS to hide the default selected option:
You can achieve it via jQuery code on page load or render. (one time only)
Working snippet:
In case you want to hide it permanently then use CSS
Working snippet: