.on(events[,selector][,data],function)
2022. 1. 4. 11:19ㆍSTUDY/JavaScript
.on(events[,selector][,data],function)
.on() 메서드는 .bind() 메서드와 마찬거지로 이벤트 핸들러를 등록하기 위하여 사용되는 메서드이다. on() 메서드는 동적으로 생성될 요소에 대해서도 이벤트 처리가 가능하다.
<body>
<button id="create">new</button>
<div></div>
</body>
$(function(){
$('#create').on('click', function(){
$('div').html('<button id="newButton">ok</button>');
});
$('body').on('click', '#newButton', function(){
console.log('click');
});
})
참고:)
https://xianeml.tistory.com/71
jQuery 제이쿼리 이벤트, Ajax 비동기 처리
🎯 자바스크립트 라이브러리 jQuery 이벤트 처리와 Ajax 비동기 처리 방법을 알아본다. jQuery 기본 Event .ready(function) HTML문서의 모든 DOM요소들이 완벽하게 사용할 준비가 되면 호출되어 function함수
xianeml.tistory.com
'STUDY > JavaScript' 카테고리의 다른 글
| 영역의 크기 메소드 (0) | 2022.01.11 |
|---|---|
| 해상도별 이미지 교체 window resize (0) | 2022.01.11 |
| Ajax로 불러온 엘리먼트의 이벤트가 작동 하지 않을때 (0) | 2021.12.31 |
| 클릭 시 Video 주소 바꾸기 (0) | 2021.12.23 |
| mobile 코딩 시 초기 세팅 (0) | 2021.12.23 |