I have a group of unordered lists items. Each list item has a data attribute with one of the following values: all deleted active inactive
I also have four radio button with the following values all deleted active inactive
What I am stuck with is setting all the list items of the selected radio button to the same color. So for deleted I set them to "red", for "active" I set them to "green" and, for "inactive" I set them to "light gray"
$('input[name="test"]').on('change', function() {
var value = this.value;
var listValue = $('li').data("status");
//$('.ul1 >li').hide();
if (value == 'All') {
//$('.ul1 >li').show();
alert('all');
}
if (value == 'deleted') {
$('.ul1 > li').each(function() {
if (listValue == 'deleted') {
$('li').css("color", "red")
}
});
}
if (value == 'active') {
//$('.ul1 >li').show();
alert('active');
}
if (value == 'inactive') {
//$('.ul1 >li').show();
alert('inactive');
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="radio" value="All" checked name="test"><label>All</label>
<input type="radio" value="deleted" name="test"><label>Deleted</label>
<input type="radio" value="active" name="test"><label>Active</label>
<input type="radio" value="inactive" name="test"><label>Inactive</label>
<ul class="ul1">
<li data-status="deleted">john</li>
<li data-status="active">mary</li>
<li data-status="inactive">bob</li>
</ul>
<ul class="ul1">
<li data-status="deleted">sally</li>
<li data-status="active">erica</li>
<li data-status="inactive">jane</li>
</ul>
<ul class="ul1">
<li data-status="deleted">ted</li>
<li data-status="active">joan</li>
<li data-status="inactive">rob</li>
</ul>
So if the deleted radio button was selected then john, sally and, ted would have their text color set to "red"
where am I going wrong
Thanks John