문제

I have an app were you can create elements, i.e. Text-element and append it to a div

And then you can also add a link to that element.

But I can't get to disable the link within the div (not removing the attr. but just disable it)

I looking for something like this:

    $('#container a').click(function() {
    e.preventDefault();
    });

To disable all links within the div.Container? Is it possible?

도움이 되었습니까?

해결책

You can use delegated events with the on method, which is designed to handle the exact situation you're describing:

$('#container').on('click', 'a', function(e) {
   e.preventDefault();
});

다른 팁

Yes, what you have is right except for the missing argument e - or just return false and forget about e.

// note the argument 'e'
$('#container a').click(function() {
    return false; // preventDefault + stopPropagation
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top