How to stop propagating event from parent div to child div

前端 未结 5 1940
一向
一向 2021-02-20 01:36

I want to stop propagate event from parent div to child div in my html. Here a simple code what I\'m trying to do:

5条回答
  •  無奈伤痛
    2021-02-20 01:48

    Instead of using e.stopPropagation, I suggest you to use unbind() method in the div

    like so...

    $('.listed-category').unbind('click');
    

    This will allow to stop the propagation effect for the .listed-category div. The method e.stopPropagation() doesn't work because it just works with parent elements and not with child elements.

    You can always create a new function and assign to the .listed-category div afterwards.. You can also check the documentation for the unbind() method at this link: http://api.jquery.com/unbind/

    I hope that helps!

提交回复
热议问题