Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to access same jquery function on click of multiple elements

Posted on 2011-09-21
3
Medium Priority
?
298 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:gaurih
  • 2
3 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 36578095
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

0
 

Author Comment

by:gaurih
ID: 36578120
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?
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36578131
no, it work : http://jsfiddle.net/scJ4h/

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

Open in new window

<a href="#" >edit</a>
<div class="entry">
...
    <input type="button" name="cancel" value="cancel" class="myclass" />
</div>

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to fix a SonicWall Gateway Anti-Virus firewall blocking automatic updates to apps like Windows, Adobe, Symantec, etc.
Aerodynamic noise is the cause of the majority of the noise produced by helicopters. The inordinate amount of noise helicopters produce is a major problem in the both a military and civilian setting. To remedy this problem the use of an aerogel coat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question