소프트웨어 이론교육/웹 프로그래밍 기본

jQuery API (2) - 기초2

마루설아 2022. 8. 2. 10:11
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>jQuery 실습 02</h1>
    <div id="box">box</div>
    <button id="changeBtn">Change</button>

    <script src="http://code.jquery.com/jquery.js"></script>
    <script>
        // Getter: .html() 
        // Setter: .html("abc")

        var fish = ['오징어', '꼴뚜기', '대구', '명태', '거북이'];
        $('#changeBtn').click(function(){
            $('#box').html('<ul>');

            fish.forEach(function(item){
                $('#box').html($('#box').html() + `<li>${item}</li>`);
            });

            $('#box').html($('#box').html() + '</ul>');
        });
    </script>
</body>
</html>

 

 

'소프트웨어 이론교육 > 웹 프로그래밍 기본' 카테고리의 다른 글

jQuery API (4) - load  (0) 2022.08.02
jQuery API (3) - map  (0) 2022.08.02
jQuery API (1) - 기초  (0) 2022.08.02
jQuery (4) - 장바구니 구현, localStorage  (0) 2022.08.01
jQuery (3) - 기초2  (0) 2022.08.01