div의 링크를 클릭하면 jq click()
을 차단하려고합니다.Jquery - 모든 "a"태그에 델리게이트 바인드
HTML
<div id="all">
<div id="test">
<a href="http://google.de">google</a>
</div>
</div>
JS
$('#test').click(function() { alert('only when i click the div'); });
$('a').click(function(e) {
e.stopPropagation();
e.preventDefault();
$('body').append(e.target.href);
});
이 코드는 잘 작동하지만, 내 콘텐츠는 동적입니다 그래서는 delegate()
솔루션이 필요합니다.
아래의 코드는 작동하지 않습니다. 하지만 왜? 뭐가 문제 야?
$('#all').delegate("a", "click", function(e)
{
e.stopPropagation();
e.preventDefault();
$('body').append(e.target.href);
});
예를
http://jsfiddle.net/Lf3hL/13/
"일을 해달라고은"문제의 매우 정확한 설명하지 않습니다 ...의 –
가능한 중복 [작동하지 JQuery와 위임과 정지 전파/라이브 기능 (http://stackoverflow.com/questions/3509249/stop-propagation-with-jquery-delegate-live-function-not-working) –