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
33
34
35
36
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<script src="js/jquery.js"></script>
</head>
<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <p>P태그</p>
    <div>DIV태그</div>
 
    <script>
 
        // var elm = $([]); // Empty jQuery Object // 빈객체를 생성할때에는 [] 일반배열이 아닌 $([]) 형태로..
        var elm = $('li'); 
        console.log(elm);
        elm = elm.add('p, div'); //확장집합에 p, div 추가
        console.log(elm);
        elm.css("background""orange");    
            
                
        // var elm = $('li').add('p') 요소를 찾고 처음부터 add()메소드를 사용하던지..
 
        // elm.add('p') 이런식으로 사용을 생각하면 안된다. 아래와 같이 사용
        // elm = elm.add('p'); // add메서드의 반환값은 새로운 jquery 객체이므로..
 
    </script>   
    
</body>
</html>


반응형
Posted by 힘없는염소