Solved

How to access same jquery function on click of multiple elements

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

Suggested Solutions

Title # Comments Views Activity
Datepicker 3 235
Add and remove classes and id's with jquery 2 2,910
Flexbox navigation issue 4 99
jquery toggle display styling 5 96
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
The goal of this blog is to: > note what has impeded us from reaching effective life on-call > provide 3 steps to mastering life on-call > highlight what will be achieved with effective life on-call
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

738 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