Click event
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
// $(document) => selector, ready => action(method)
// ready => window.onload와 동일한 것임
/*
(document)=> css 선택 여기서는 document선택함
ready => window.onload와 거의 동일함
$(document).ready(); 앞에는 선택 뒤에는 실행하는 것
ready() => 안에는 함수가 들어옴
*/
$(document).ready(function(){
// getElementsByTagName("p")와 동일
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you click on me, i will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>
※ 실행화면
'jQuery 수업' 카테고리의 다른 글
jQuery-6(이벤트 fadeIn(), fadeOut(), fadeTo(), fadeToggle()) (0) | 2020.02.19 |
---|---|
jQuery-5(이벤트 toggle) (0) | 2020.02.19 |
jQuery-4(이벤트 hide(), show()) (0) | 2020.02.19 |
jQuery-3(마우스 이벤트, mouseenter, mouseleave, mousedown, mouseup) (0) | 2020.02.19 |
jQuery-2(더블클릭) (0) | 2020.02.19 |