Reputation: 1071
I'm trying make a form. Where when you select an option, the empty value is removed and the color changes.
But, when you change the option, all empty values are being removed at the same time.
What i have to do to resolve this?
$(document).ready(function() {
$('.changeMe').change(function(){
$('.empty').remove();
$(this).css({'color':'black'});
});
});
Thanks in advance
Upvotes: 1
Views: 65
Reputation: 81
OK, try this:
$(document).ready(function() {
$('.changeMe').change(function(){
var $this = $(this);
$this.parents("div").find('.empty').remove();
$this.removeClass("blue");
$this.addClass("black");
});
});
Basically, you need first to find the parent div (containing the row) and remove any .empty descendants.
Upvotes: 0
Reputation: 15112
$('.changeMe').change(function(){
$('.empty',this).remove();
$(this).css({'color':'black'});
});
You are removing all classes with empty
. You have to only remove the one which is related. So, use this
.
Upvotes: 1