Hey friends, Today I am going to show you how you can create a select box with an icon or images.
Actually, it’s a trick. A jQuery tricks
I have created a simple jQuery plugin for you. For more detail checkout GitHub repo.
Create a select element with a unique id
. If you want to add images as an icon to option list
then add the image URL to data-icon
attribute otherwise assign font-awesome icon class
to data-icon
like in given example:
<select id="example" name="currency"> <option value="btc" data-icon="btc.png"> Bitcoin (BTC) </option> <option value="eth" data-icon="eth.png"> Ethereum (ETH) </option> <option value="bch" data-icon="bch.png"> Bitcoin cash (BCH)</option> </select>
Initialize the plugin like below:
$( selector ).IconSelectBox( isImage ); // isImage: boolean;
To add image isImage
should be true
and for icons it should be false
;
Finally, you can get the value from your created select element
. like if you create an element #select-action
then you can get value like this
$('#select-action').val();
Nothing complicated.
Today we are going to learn about managing multiple PHP versions on ubuntu with xampp.…
Let's understand about how to use coding to improve your website's SEO. In today’s computerized…
Let's understand the most important linux commands for web developers. Linux, as an open-source and…
Today we are going to discuss top 75+ Laravel interview questions asked by top MNCs.Laravel,…
Today we will discuss about the Mailtrap integration with laravel 10 .Sending and receiving emails…
Today we are going to integrate FCM (Firebase Cloud Messaging) push notifications with ionic application.Firebase…
View Comments
would this work with a datalist and setting the value on that? rather than a select
Definitely, abi
If you found any issue, please let me know, I'll fix that