JQUERY

JQUERY 클릭 이벤트와 멀티 seleter사용하기

JDK's blog 2015. 11. 29. 21:56

안녕하세요 jquery에서 seleter와 click이벤트에 대해서 알아보겠습니다.

 

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
<meta charset="utf-8"/>
<html>
<head>
<title>JDK의 블로그</title>
 
<!-- jquery를 불러옵니다. jquery.com download 페이지를 참조해주세요 -->
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
 
<script language="javascript">
    $(document).ready(function(){
        //같은 event를 여러개로 지정했습니다.
        //#test는 ID가 test의 경우에 처리합니다.
        //.test는 Class가 test의 경우에 처리합니다.
        //span은 태그 이름이 span인 경우 처리합니다.
        //div.span은 div태그 밑에 span태그인 경우에 처리합니다.
        $("#test,.test,span,div.span").click(function(){
            alert("jdk's blog Jquery");
        });
    });
</script>
</head>
<body>
<input type='button' class='test' value='버튼'/>
 
<input type='button' id='test' value='버튼'/><br/>
<span>버튼</span><br/>
<div>
    <span>div 버튼안에span</span>
</div>
</body>
</html>
cs