클릭하면 해당 DIV 내부에 다른 DIV가 추가됩니다. 그런 다음 새로 추가 된 DIV를 클릭하면 제거됩니다.jQuery에서 중첩 된 클릭
HTML
<div id="container"></div>
jQuery를
$('#container').on('click', function(e){
// Add other DIV
$(this).append('<div class="other">XYZ</div>');
e.stopPropagation();
// Remove other DIV
$('div.other').bind('click', function(event){
$(this).remove();
event.stopPropagation();
});
});
어떻게 효율적으로 내가 아이 div를 많이해야 할 계획이 방법입니까?
매우 효과적이라고 생각합니다 ... – tymeJV
"많이"무엇인가요? 일반적으로 선택기와 일치하는 모든 요소가 아닌 추가 된 요소에만 클릭을 첨부해야합니다. 지 수십만 개의 요소를 삽입해야하는 경우 위임 된 이벤트 처리기가 더 좋습니다. – adeneo
모든 클래스가'other'를 가지고 있다면, 간단히'$ ("# container")를 할 수 있습니다 on ("click", ".other", function() {' – tymeJV