jQuery

[jQuery] Select all checkboxes, create deselect all

OOQ 2022. 7. 25. 17:34
728x90
SMALL
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>jQuery</title>
    <script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
    <script>
      $( document ).ready( function() {
        $( '.check-all' ).click( function() {
          $( '.ab' ).prop( 'checked', this.checked );
        } );
      } );
    </script>
  </head>
  <body>
    <form>
      <p><input type="checkbox" name="all" class="check-all"> <label>Check ALL</label></p>
      <hr>
      <p><input type="checkbox" name="cb1" class="ab"> <label>Checkbox 1</label></p>
      <p><input type="checkbox" name="cb2" class="ab"> <label>Checkbox 2</label></p>
      <p><input type="checkbox" name="cb3" class="ab"> <label>Checkbox 3</label></p>
      <p><input type="checkbox" name="cb4" class="ab"> <label>Checkbox 4</label></p>
    </form>
  </body>
</html>

728x90
LIST