Solved

How to access same jquery function on click of multiple elements

Posted on 2011-09-21
3
287 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 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now