Skip to content

How correctly change checkbox values using jQuery? #2255

@uralbash

Description

@uralbash

For example, I want to checked/unchecked all item by <input type="checkbox" id="all" />. In my case, checked attribute is changed but it does not display (http://jsfiddle.net/Lvmy64w0/2/)

  <form action="#">
    <p>
      <input type="checkbox" id="all" />
      <label for="all">SelectAll</label>
    </p>
    <p>
      <input class="item" type="checkbox" id="test5" />
      <label for="test5">Red</label>
    </p>
    <p>
      <input class="item" type="checkbox" id="test6" checked="checked" />
      <label for="test6">Yellow</label>
    </p>
    <p>
      <input type="checkbox" class="filled-in item" id="filled-in-box" checked="checked" />
      <label for="filled-in-box">Filled in</label>
    </p>
    <p>
      <input type="checkbox" id="test7" checked="checked" disabled="disabled" class="item" />
      <label for="test7">Green</label>
    </p>
      <p>
        <input type="checkbox" id="test8" disabled="disabled" class="item" />
        <label for="test8">Brown</label>
    </p>
  </form>
$(function(){
    $("#all").click(function () {
          $('.item').attr('checked', this.checked);
    });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions