<!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="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
</head>
<body>
    <script>
        $(document).ready(function(){
            $("#btn1").on('click',function(){
                let mText = $("#test").text();
                alert(mText);
            });
            $("#btn2").on('click',function(){
                
                //alert($("#test").html());
                let node1 = $("#test").html();
                let node2 = document.querySelector("#test");
                console.log(typeof node1);
                console.log(typeof node2);
            });
            $("#btn3").on('click',function(){
                
                alert($("#input-test").val());
            });
        });
    </script>
    <p id="test">후미진 <input type="text" id="input-test" value="그늘진어느언덕"></p>
    <button id="btn1">글자 가지고 오기</button>
    <button id="btn2">HTML 요소 가지고 오기</button>
    <button id="btn3">value 요소 가지고 오기</button>
</body>
</html>

 

'JS' 카테고리의 다른 글

Ajax 비동기 통신 예제풀이  (0) 2023.05.08
비동기 통신  (0) 2023.05.08
제이쿼리란  (0) 2023.05.08
핵심 부분을 예제문제 풀어보기  (0) 2023.05.08
예제 (값 받아오기)  (0) 2023.05.08

+ Recent posts