change Icon color and background color based on select box using jquery | Sanwebcorner

change Icon color and background color based on select box using jquery

In this post i am going to tell you how to change icon background color and color based on the select box with the help of jquery and javascript. This is one of the simple methods just using if condition will done this concept with the help of javascript.



This type of concept is really helpful in some of the application development like badge customization or commendation bar. When you click the select box it opens a dropdown list and shows the list of colors, when you choose the bg color from this list it automatically applies the background color to the particular icon, Here i used the plus icon from the help of font awesome icon. and you can also choose the font color with the help of the other select box.

The below example have the codes you can customize this according to the your wish and also available demo page you can view the result of this program. I hope this post is really helpful to you.

Html Code for Change icon color and bg color using selectbox:

<h1>change Icon color and background color based on select box using jquery</h1>
<div class="color" style="width:205px; padding:66px; border:1px solid #f1f1f1;">
<i class="fa fa-plus fa-6 imgcolor" aria-hidden="true" style="font-size: 16em; "></i>
</div>
<select runat="server" style="background-color:#f1f1f1;color:#000;padding:15px;margin: 20px 0px 20px 0px;" id="select">
<option value="white" style="background-color: white;">Select background</option>
<option value="silver" style="background-color: silver;">Silver</option>
<option value="gold" style="background-color: #ffd700;">Gold</option>
</select>
<select runat="server" style="background-color:#f1f1f1;color:#000;padding:15px;margin: 20px 0px 20px 20px;" id="select-color">
<option value="black" style="background-color: white;">Select Icon color</option>
<option value="pink" style="background-color: pink;">pink</option>
<option value="purple" style="background-color: purple;">purple</option>
<option value="red" style="background-color:red;">Red</option>
</select>

Jquery for Change icon color and bg color using select box:

<script>
$('#select').change(function(){
if($(this).val() == 'silver'){
$(".color").css('background-color', '#e1e1e1');
}
if($(this).val() == 'gold'){
$(".color").css('background-color', '#ffd700');
}

if($(this).val() == 'white'){
$(".color").css('background-color', 'white');
}

});
</script>
<script>
$('#select-color').change(function(){
if($(this).val() == 'purple'){
$(".imgcolor").css('color', '#800080');
}
if($(this).val() == 'pink'){
$(".imgcolor").css('color', 'pink');
}

if($(this).val() == 'white'){
$(".imgcolor").css('color', 'white');
}
if($(this).val() == 'red'){
$(".imgcolor").css('color', 'red');
}
});
</script>

Post a Comment

Labels

360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll create random number Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient hide menu Horizontal News ticker Hover Htm Html html dropdown html form html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript Jquery js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form multi-select-checkbox Multi-Step-form Multiple File Upload in PHP mysql News ticker on hover change text to image our team page password generator password strength checker Photoshop PHP php mailer populate html selectbox Popup image on click the link pure css Question type form random number generate Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips whatsapp link website Youtube