0
I use the function below to add CSS classes (blue, red, pink...) in a DIV ". container" from a select "#selcolor". Is it possible for me to use this same function in other select tags with different Ids? In this case the classes (blue, red, pink...) would not be added in the DIV ". container", i.e., the "div_action" variable of the function would have to be modified.
function select_changed() {
jQuery('select#selcolor').each(function() {
var selected = jQuery(this).val();
var div_action = '.container';
if(selected == '') {
jQuery(div_action).addClass('');
}
if(selected == 'blue') {
jQuery(div_action).addClass('blue');
} else {
jQuery(div_action).removeClass('blue');
}
if(selected == 'pink') {
jQuery(div_action).addClass('pink');
} else {
jQuery(div_action).removeClass('pink');
};
if(selected == 'red') {
jQuery(div_action).addClass('red');
} else {
jQuery(div_action).removeClass('red');
};
});
}
$('select#selcolor').change(function() {
select_changed();
});
Thanks for the answer. So, but the second select tag in html will have a different ID. For example, select#selcolor adds the classes in div ". container", while another select, this #selcolor2 call adds the classes in another div.
– Rafael
Then edit your question to include these details.
– Renan Gomes
I didn’t get it, was that right? Only accept the answer if you are correct @Rafael
– Renan Gomes