迭代Div并使用jquery检查check子元素

迭代Div并使用jquery检查check子元素,jquery,html,Jquery,Html,我有一个div标记,在这个div中我有子元素,我想得到所有这些子元素,并检查子元素是否为Checkbox,如果子元素为Checkbox,那么我需要选中该复选框 <div class="options" > <input type="checkbox" class='roles' /> </div> 选中此项 $('.options').children('input[type="checkbox"]').each(function () {

我有一个div标记,在这个div中我有子元素,我想得到所有这些子元素,并检查子元素是否为Checkbox,如果子元素为Checkbox,那么我需要选中该复选框

  <div class="options" >
  <input type="checkbox" class='roles' />
  </div>
选中此项

$('.options').children('input[type="checkbox"]').each(function () {
    this.checked = true; 
});


+1代表+1。当与太多选择器一起工作时,很难写出kout@RajaprabhuAravindasamy
$('.options').children('input[type="checkbox"]').each(function () {
    this.checked = true; 
});
$('.options').children().filter('input[type="checkbox"]').each(function () {
    this.checked = true; 
});