[Solved] jquery do something after element clicked every 5 times [closed]
Here is a really simple solution which is also scalable: $(function() { $(‘button’).click(function() { var btn = $(this); var counter = ((btn.data(‘click-counter’) || 0) + 1) % 5; btn.text(‘Click me (‘ + counter + ‘)’); btn.data(‘click-counter’, counter); btn.toggleClass(‘remove’, !counter); }); }); button.remove { background-color: red; } <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <button>Click me</button> <button>Click me</button> <button>Click me</button> solved … Read more