0

How to stop parent event trigger while clicking child event?

CODE:

$('body').on('click', 'cs-placeholder', function(e) {
    //* Disable dropdown in modals that aren't contacts
    if( $(e.target).parents(".modal").length === 0 || $(e.target).parents("#contact").length === 1 ) {
        if($(this).hasClass('active')) {
            alert('close');
            $(this).removeClass('active');
        }
    } else {
        alert('open');
        $('.cs-placeholder').removeClass('active');
        $(this).toggleClass('active');
    }
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vinod
  • 1
  • 5

1 Answers1

0
$("body").on('click', '.cs-placeholder', function(e) {
    e.stopPropagation();
});

If you want to read more on .stopPropagation().