Hamish
Hamish

Reputation: 87

Iterate through Div and check if the check child element using jquery

I have a div tag and inside that Div i have child elements and i want to get all those child elements and check if the child element is Checkbox,If the child element is checkbox then i need that Checkbox to be checked.

  <div class="options" >
  <input type="checkbox" class='roles' />
  </div>

this is how it looks and there will be unspecified number of checkboxes with same class.

    $('.options').children('input').each(function () {
        alert(this.value); 
    });

Upvotes: 3

Views: 1136

Answers (1)

Shaunak D
Shaunak D

Reputation: 20636

Check this Fiddle Demo

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

Or

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

Upvotes: 1

Related Questions