Link to home
Start Free TrialLog in
Avatar of gaurih
gaurih

asked on

How to access same jquery function on click of multiple elements

Hi,
My code snippet:
<a href="#" >edit</a>
<div class="entry">
...
<input type="button name="cancel">
</div>

Currently I have written the code to handle the current object and slidetoggle the div tag. but the same code is not working for onclick of cancel button because my code was like:
$(this).closest(div).siblings(div.entry).slidetoggle();

Can you give me some alternate solution to handle both scenarios

Avatar of leakim971
leakim971
Flag of Guadeloupe image

use a common class name for all the element, for example : myclass

so use :

$(".myclass").click(function() { // click event for example
       $(this).closest(div).siblings(div.entry).slidetoggle();
}) 

Open in new window

Avatar of gaurih
gaurih

ASKER

The issue here is
$(this).closest(div).siblings(div.entry).slidetoggle(); is not getting triggered while I click the cancel button because it is part of the div.

Is there any solution to handle that?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial