Answer the question
In order to leave comments, you need to log in
How to mark elements in parent?
Hello. I have some code like this:
<li class="close">
<input type="checkbox" id="check_2" name="tags[]"> <label for="check_2">Первый чакбокс</label>
<ul>
<li>
<input type="checkbox" id="check_118" name="tags[]"> <label for="check_118">Второй чекбокс</label>
<ul>
<li>
<input type="checkbox" id="check_119" name="tags[]"> <label for="check_119">Третий чекбокс</label>
</li>
</ul>
</li>
</ul>
</li>
Answer the question
In order to leave comments, you need to log in
.parents() will help you find the parent elements for each checkbox.
.children() will help you find checkboxes in parent elements.
Example (parent checkboxes will have the same value as the selected one):
(function($) {
$('input[type="checkbox"]').on('change', function() {
var isChecked = $(this).prop('checked');
$(this).parents().children('input[type="checkbox"]')
.prop('checked', isChecked);
})
})(jQuery);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question