<!DOCTYPE HTML>
<html lang="ko">
  <head>
    <meta charset="UTF-8">
    <title>prop() 메서드</title>
    <script src="jquery-3.3.1.min.js"></script>
  </head>
  <body>
    <input type="checkbox" id="html"><label for="html">html</label>
    <input type="checkbox" id="css"><label for="css">css</label>
  </body>
</html>
$(document).ready(function () {
  console.log($("input:checkbox").eq(0).attr("checked"));
  console.log($("input:checkbox").eq(1).prop("checked"));
  $("input:checkbox").eq(0).attr("checked", "checked");
  $("input:checkbox").eq(1).prop("checked", true);
  console.log($("input:checkbox").eq(0).attr("checked"));
  console.log($("input:checkbox").eq(1).prop("checked"));
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js