I have several elements that got the .active class by clicking on them. Now I donβt need any clicks in any .active class. I have many click functions, which makes the active element. Thus, to prevent clicking on active classes, I wrote a prevent function in another place and call them inside each click function. But that did not work.
$('body').on('click', '#one', function() { $(this).addClass('active'); // do something more noClickOnActive(); }); $('body').on('click', '#two', function() { $(this).addClass('active'); // do something more noClickOnActive(); }); function noClickOnActive() { $('body').on('click', '.content.active', function(event) { event.preventDefault() event.stopPropagation(); }); };
How to make it work?
Script work
source share