1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
</head>
<body>
    <div id="wrapper">
        <div id="box1">box1</div>
        <div id="box2">
            <h4>h4태그</h4>
        </div>
    </div>
    <script src="js/jquery.js"></script>
    <script>
 
        var $div = $("<div>");                //div 객체생성
        var $h2 = $('<h2>').text("h2태그");
        var $p = $('<p>').text("p태그");
        var $span = $("<span>").text("span태그");
        
        $div.append($h2,$p,$span)        // $div의 (마지막)자식 순서로  h2, p, span을 추가
            .appendTo("#wrapper");       // $div를 #wrapper의 (마지막) 자식으로 추가
        
 
        var $h3 = $('<h3>').text("h3태그");
        
        $("#box2").prepend($h3)            //#box2의 (첫번째)자식 으로 h3 추가 
                  .prependTo('#wrapper');  //#box2를 #wrapper의 첫번째 자식으로 추가
        
    </script>
</body>
</html>



반응형
Posted by 힘없는염소