728x90
append 한 button에 클릭이벤트를 주니 이런 오류 메시가 출력.
(index):1 Uncaught ReferenceError: 함수명 is not defined
at HTMLButtonElement.onclick ((index):1)
원인 : 동적으로 추가된 태그는 이벤트가 동작되지 않음. = 로드되었을 때 존재하지 않는 태그에 대해서는 이벤트를 걸 수 없는 것
$(document).on('click / change 등등의 이벤트', '이벤트 적용할 타깃 태그', 동작 함수(){});
또는
$('.부모 이름').on('click', '.걸고 싶은 대상', function() {
넣을 소스;
});
출처 : https://stackoverflow.com/questions/15420558/jquery-click-event-not-working-after-append-method
Jquery click event not working after append method
So I have this button which adds a new row to the table, however my problem is that it does not listen to the .new_participant_form click event anymore after the append method has taken place. htt...
stackoverflow.com
'js' 카테고리의 다른 글
| [JavaScript] input Box 자동 submit 막는 방법 3가지 (0) | 2021.11.04 |
|---|---|
| [jQuery] 파일 업로드 input type = 'file' 다중으로 생성하기 (2) | 2021.10.26 |
| [AJAX] 다중 fileupload / formData 이용하여 JSON 파라미터 넘기기 & 파일업로드 구현 (1) | 2021.10.22 |
| [JavaScript] .js 파일에서 contextPath 구하여 사용하기 (sessionStorage) (0) | 2021.09.23 |
| [jQuery] ajax success html에서 원하는 요소 찾기 (0) | 2021.09.15 |