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

jQuery (2) - callback

마루설아 2022. 8. 1. 12:04
<!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>
    <script src="http://code.jquery.com/jquery.js"></script>
</head>
<body>
    <h1>Hello jQuery</h1>

    <script>
        // jQuery 라이브러리에 새 기능 추가(플러그인)
        $.fn.changeColor = function(color, callback){
            this.css({'color': color});
            callback(this);
        }
    </script>

    <script>
        $('h1').changeColor('red', function(target){
            alert('적용 완료');
        });
    </script>
</body>
</html>