This website uses cookies to ensure you get the best experience on our website.
To learn more about our privacy policy Click here<pre title=""><html>
<head>
<title>JQuery-Setting Icon in the Dropdown List Box</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ivaynberg.github.io/select2/select2-3.4.5/select2.js" type="text/javascript"></script>
<link href="http://ivaynberg.github.io/select2/select2-3.4.5/select2.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<style>
body {
padding: 10px;
}
.fa-dot-circle-o {
float: right;
line-height: 20px;
color:green;
}
</style>
</head>
<body>
<select id="myval" style>
<optgroup label="My First Group">
<option value="0" data-active="0">Hello!!!</option>
<option value="1" data-active="1">Dot Circle 1</option>
<option value="2" data-active="0">Dot Circle 2</option>
</optgroup>
<optgroup label="My Second Group">
<option value="2" data-active="0">Dot Circle 3</option>
<option value="3" data-active="1">Dot Circle 4</option>
<option value="3" data-active="0">Dot Circle 5</option>
</optgroup>
</select>
<script>
$("#myval").select2({
width: "50%",
formatResult: function (state) {
if (!state.id) return state.text;
if ($(state.element).data('active') == "0") {
return state.text + "<i ></i>";
} else {
return state.text;
}
},
formatSelection: function (state) {
if ($(state.element).data('active') == "0") {
return state.text + "<i ></i>";
} else {
return state.text;
}
}
});
</script>
</body>
</html></pre>
<pre title=""><html>
<head>
<title>JQuery-Setting Icon in the Dropdown List Box</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ivaynberg.github.io/select2/select2-3.4.5/select2.js" type="text/javascript"></script>
<link href="http://ivaynberg.github.io/select2/select2-3.4.5/select2.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<style>
body {
padding: 10px;
}
.fa-dot-circle-o {
float: right;
line-height: 20px;
color:green;
}
</style>
</head>
<body>
<select id="myval" style>
<optgroup label="My First Group">
<option value="0" data-active="0">Hello!!!</option>
<option value="1" data-active="1">Dot Circle 1</option>
<option value="2" data-active="0">Dot Circle 2</option>
</optgroup>
<optgroup label="My Second Group">
<option value="2" data-active="0">Dot Circle 3</option>
<option value="3" data-active="1">Dot Circle 4</option>
<option value="3" data-active="0">Dot Circle 5</option>
</optgroup>
</select>
<script>
$("#myval").select2({
width: "50%",
formatResult: function (state) {
if (!state.id) return state.text;
if ($(state.element).data('active') == "0") {
return state.text + "<i ></i>";
} else {
return state.text;
}
},
formatSelection: function (state) {
if ($(state.element).data('active') == "0") {
return state.text + "<i ></i>";
} else {
return state.text;
}
}
});
</script>
</body>
</html></pre>