This is a somewhat constructed question, which should hopefully teach me do write more maintainable jQuery.
I have a button, which should slideToggle another element.
I know I can do like this:
$('.button').click(function(){
$('.other-element').slideToggle();
});
However, I would like to just fire an event when clicking the .button, and then 'catch' the event on the .other-element. I thought I would be able to do like this:
$('.button').click(function(){
$(this).trigger('customEvent');
});
$('.other-element').on('customEvent', function() {
$(this).slideToggle();
});
This ofc results in more code, and in this specific example, its probably not a good idea, but I like the division between event firing and catching.
How do I do this the right way?