• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>jQuery Style</title>
7
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
8
    <script>
9
        $(function() {
10
            $("#setBtn").on("click", function() {
11
                $("input[value='jquery']").prop({   // <input>요소 중에서 value 값이 "jquery"인 요소를 선택한 후
12
                    checked: true                   // 해당 요소에 checked 프로퍼티를 true 값으로 설정함.
13
                });
14
            });
15
            $("#removeBtn").on("click", function() {
16
                $("input[value='jquery']").removeProp("checked");   // 해당 요소에서 checked 프로퍼티를 삭제함.
17
            });
18
        });
19
    </script>
20
</head>
21
​
22
<body>
23
​
24
    <h1>.prop() 메소드</h1>
25
    <form>
26
        <input type="checkbox" name="lecture" value="html" checked> HTML <br>
27
        <input type="checkbox" name="lecture" value="jquery"> jQuery
28
    </form>
29
    <br>
30
    <button id="setBtn">jQuery에 프로퍼티 값 설정</button>
31
    <button id="removeBtn">프로퍼티 제거</button>
32
    
33
</body>
34
​
35
</html>