출처: https://bumcrush.tistory.com/182 [맑음때때로 여름]

 

 

1) 문서 객체의 내부 검사

    <script>
        $(document).ready(function() {
            //html( ) 메서드 - Getter
            console.log('div->', $('div').html());
            //text( ) 메서드 - Getter
            console.log('div->', $('div').text());
        });
    </script>

</head>

<body>

    <div>

        <h1> 네이버 </h1>
        <h1> 카카오 </h1>
        <h1> 페이스북 </h1>

    </div>

 

2) 문서 객체의 내부 추가

            $('button').first().click(function() {
                $('div>h1').html('<h4>html</h4>');
            });

            $('button').first().click(function() {
                $('div>h1').text('<h4>text</h4>');
            });

 

 

 

            $('button').first().click(function() {
                $('div>h1').html(function(index){
                    return '<h'+(index+2)+'>안녕!</h'+(index+2)+'>';            
                });

            $('button').first().click(function() {
                $('div>h1').text(function(index){
                    return '<h'+(index+2)+'>안녕!</h'+(index+2)+'>';            
                });              
            });

 

3) 문서 객체 제거

            $('button').first().click(function() {
                $('div').empty();
            });

            $('button').first().click(function() {
                $('div>h1:first').remove();
            });

+ Recent posts