I have the checkboxes and I want to check the checkbox with specific value id checked in jquery
I want to check the check box meetingcategory with value 'test' is checked if checked need to uncheck the relatedto checkbox lead and contacts.
$(".meetingcategory input").click(function(){
if($(this).val()=='test') //need to check is checked
{
$('.relatedto input[value="Leads"]').prop('checked', false);
$('.relatedto input[value="Contacts"]').prop('checked', false);
}
else{
$('.relatedto input[value="Leads"]').prop('checked', true);
$('.relatedto input[value="Contacts"]').prop('checked', true);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='meetingcategory'>
<input type="checkbox" title="test" id="ms-opt-124" value="test">test
<input type="checkbox" title="test1" id="ms-opt-124" value="test1">test1
</div>
<div id='relatedto'>
<label for="ms-opt-1"><input type="checkbox" title="Leads" id="ms-opt-1" value="Leads" checked>Leads</label>
<label for="ms-opt-1"><input type="checkbox" title="Contacts" id="ms-opt-1" value="Contacts"
checked>Contacts</label>
<label for="ms-opt-1"><input type="checkbox" title="Blank" id="ms-opt-1" value="Blank" checked>Blank</label>
</div>
relatedtois an id, not a class, so you should use#relatedtoinstead of.relatedto. Also, ids must be unique so you can't have all the checkboxes with the same id.