15.1.29 jQuery 이 벤 트 !
( 1 ) 이벤트 기본 연결
1)
$(selector).on(eventName, function(event) {} )
2)
$(selector).on(object)
ex)
<script>
$(document).ready(function(){
$('h1').on('click',function(){
$(this).html(function(index, html){
return html + '+';
});
});
$('h1').on({
mouseenter: function (){
$(this).addClass('reverse');
},
mouseleave: function (){
$(this).removeClass('reverse');
}
});
});
</script>
</head>
<body>
<h1>Header-0</h1>
<h1>Header-1</h1>
<h1>Header-2</h1>
</body>
----------> h1 태그에 클릭 하면 +가 추가되고 위에 올려놓으면 색이 반전되도록 하는것
( 2 ) 매개변수 context
<script>
$(document).ready(function(){
$('div').click(function(){
var header = $('h1', this).text();
var paragraph = $('p', this).text();
});
})
</script>
-----> this 가 있기 때문에 선택한 'div'에 대해서만 내용이 저장된다?
출처 : 모던 웹을 위한 javascript + jquery 입문