Solved

How to access same jquery function on click of multiple elements

Posted on 2011-09-21
3
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

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 82

Accepted Solution

by:
leakim971 earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Getting to know the threat landscape in which DDoS has evolved, and making the right choice to get ourselves geared up to defend against  DDoS attacks effectively. Get the necessary preparation works done and focus on Doing the First Things Right.
With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

627 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