I am programming something that has two buttons with the same functionality.
Rather than putting all the information from the first button into the second one, I added an even handler to the second to trigger a click on the first so the same code will be run.
I’m using the jQuery framework so if possible could I get suggestions in jQuery format.
This is the code I was using for the event handler:
$(document).on('click', '.enlargeComments', function(){
$(this).prev('.commentsLink').trigger('click');
});
The button with all the functionality is created by a PHP class, so getting the information to place it onto the second will not work, also giving it an identifying class would also mean making additional changes to the class which isn’t ideal to be honest.
However now I have another button which comes in between these two and my event handler no longer works… I need a solution to get my original one workings so no suggestions to change the way it’s currently working please.
You can use
.prevUntil(sel).prev()to do this: