0

I append <a> tag to my div :

$('<a class="dz-jcrop" href="http://www.google.com"  >google</a>').appendTo('.dz-image-preview');

I want to stop propagation for <a> tag .. but when I try just to select the element I can't. I use the following code to log to test if my element is selected :

$(document).on('click', '.dz-jcrop', function(){ 
    console.log('me');
}); 

It doesn't get logged and the element is not selected. How to stop propagation to appended element?

Ram
  • 3,032
  • 10
  • 39
  • 56
AiD
  • 947
  • 3
  • 14
  • 40

1 Answers1

0

see this example: http://jsfiddle.net/kevalbhatt18/6sjzada9/

Use return false;

$('<a class="dz-jcrop" href="http://www.google.com"  >google</a>').appendTo('.dz-image-preview');
$(document).on('click', '.dz-jcrop', function(event){
    console.log('me');
    return false;
});

what is different between return and stopPropagation See this link: https://stackoverflow.com/a/30475572/4696809

Community
  • 1
  • 1
Keval Bhatt
  • 5,990
  • 2
  • 22
  • 40