I feel like this function will cause more problems than it's supposed to solve. Here is why:
A function should do a specific task, that is self descriptive by the function name. Having a function that does a lot of different things depending on it's parameters is not easy to use and read.
Unfortunately `toggleClick` does not do what it says, and it uses up brain matter every time you have to use it.
If I somehow ended up having to work with this code i'd have to run the `if` statements in my head before writing them as parameters to the function.
> If the user clicks the first element, I should toggle the third child of that element,<br>
> but only if this variable is TRUE, otherwise the parent itself should toggle instead
If I had to use something like this, it is such a specific use case that I'd propably write the code I just thought about, instead of trying to figure out what this function does.
What I'd do:
If I can edit the markup, or the interacting elements are not decided dynamically, I'd set IDs to the elements I want to interact and do a simple
$('#myelement').on('click', function(){
$('#target_element').toggle();
});
It might be 3 lines long, but you know what it does the moment you read it. If you want to mimic the use of your `toggleClick` you can try this instead:
// When I click the 2nd child of #my_element...
$('#my_element :eq(0)').on('click', function(){
// Toggle the fifth child of the #target_element
$('#target_element :eq(4)').toggle();
});