0

I am trying to select individual selection and in hidden a input checkbox in an un-ordered list.

Issue: When I click on one it selects all instead of one I need just like checkbox in list with hidden input checkbox here is my code shared in jsFiddle

<ul class="checkbox_list">
    <li>
        ravi
        <p>2343534656 - U44BB387587</p>
        <input type="checkbox" class="input_class_checkbox" id="c1">
    </li>
    <li>
        arvi
        <p>2343534656 - U444BB387587</p>
        <input type="checkbox" class="input_class_checkbox" id="c2">
    </li>
    <li>
        jiva
        <p>2343534656 - 444BB387587</p>
        <input type="checkbox" class="input_class_checkbox" id="c3">
    </li>
</ul>

1 Answer 1

2

You need to use clicked element context this to target correct element:

$('.checkbox_list li').on('click',function(){
    $(this).toggleClass('checked').prev().prop('checked',$(this).is('.checked'));
});

Working Demo

Sign up to request clarification or add additional context in comments.

2 Comments

not only the class "checked" in ".checkbox_list li", i want to add the class "checked" in class="class_checkbox"
@DivyaSharma: $(this).find('.input_class_checkbox').addClass('checked')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.