본문 바로가기
jQuery

jQuery delegate() - 버튼 만들기

by 호랭형님 2020. 1. 18.

 

 


 

 

 

 


$(document).delegate('.btn', 'click', function(){ 

    $('<button>', {'type' : 'button', 'class' : 'btn', 'text': '새로운버튼'}).appendTo('#result');

})  --> 버튼 클릭 시 '새로운버튼' result div에 추가하기

 

$('#stop').on('click', function(){

     $(document).undelegate('click');

}) --> id: stop 버튼 클릭 시 버튼 생성 이벤트 종료시켜 새로운 버튼 추가 막기

 

 

댓글