카테고리 없음

Jquery VS JS

Canyi 2022. 11. 3. 10:57

JS

<!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>Javascrpt</title>
</head>
<body>
    <script>
        window.onload = function() {
            console.log('html이 준비되면 실행');
            document.getElementById('pp').style.color = 'pink';
        }
        function fn_click(color) {
            document.getElementById('pp').style.color = color;
        }
    </script>

    <p id="pp">Hello World : Javscript</p>
    <button id="red" onclick="javascript:fn_click('red')">red</button>
    <button id="blue" onclick="javascript:fn_click('blue')">blue</button>
</body>
</html>

JQUERY

<!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>Javascrpt</title>
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
    <script>
        window.onload = function() {
            console.log('html이 준비되면 실행');
            $('#pp').css('color', 'pink');
        }
        function fn_click(color) {
            $('#pp').css('color',color);
        }
    </script>

    <p id="pp">Hello World : Jquery</p>
    <button id="red" onclick="javascript:fn_click('red')">red</button>
    <button id="blue" onclick="javascript:fn_click('blue')">blue</button>
</body>
</html>