I have a select list of genders.
Code:
<select>
<option>male</option>
<option>female</option>
<option>others</option>
</select>
I want to use an image in drop down list as drop-down-icon.jpeg.
I want to add a button in place of drop down icon.
How to do that?
With countries, languages or currency you may use emojis.
Works with pretty much every browser/OS that supports the use of emojis.
You already have several answers that suggest using JavaScript/jQuery. I am going to add an alternative that only uses HTML and CSS without any JS.
The basic idea is to use a set of radio buttons and labels (that will activate/deactivate the radio buttons), and with CSS control that only the label associated to the selected radio button will be displayed. If you want to allow selecting multiple values, you could achieve it by using checkboxes instead of radio buttons.
Here is an example. The code may be a bit messier (specially compared to the other solutions):
I tried several jquery based custom select with images, but none worked in responsive layouts. Finally i came accross Bootstrap-Select. After some modifications i was able to produce this code.
Code and github repo here
For those wanting to display an icon, and accepting a "black and white" solution, one possibility is using character entities:
By extension, your icons can be stored in a custom font. Here's an example using the font FontAwesome: https://jsfiddle.net/14606fv9/2/ https://jsfiddle.net/14606fv9/2/
One benefit is that it doesn't require any Javascript. However, pay attention that loading the full font doesn't slow down the loading of your page.
Nota bene: The solution of using a background image doesn't seem working anymore in Firefox (at least in version 57 "Quantum"):
UPDATE: As of 2018, this seems to work now. Tested in Chrome, Firefox, IE and Edge
Another jQuery cross-browser solution for this problem is http://designwithpc.com/Plugins/ddSlick which is made for exactly this use.