Solved

jQuery: Fire only once with multiple binds

Posted on 2012-03-28
4
414 Views
Last Modified: 2012-04-15
This fires twice if I click on my radio button:

 $('.xyz input').bind('change click', function(){
  alert('Hello');
 });

Open in new window


How can I get it to fire only once, either if is clicked on or changed?
0
Comment
Question by:hankknight
  • 2
4 Comments
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 400 total points
ID: 37777391
use this:-
$('.xyz input').click(function(){
  alert('Hello');
 });

Open in new window

0
 
LVL 42

Expert Comment

by:David S.
ID: 37778635
I agree with BuggyCoder.  The change event is only triggered on radio buttons in IE (or at least some versions of it) after the radio button loses focus, so it's best to just use the click event.
0
 
LVL 16

Author Comment

by:hankknight
ID: 37779687
Will click fire even if the radio is changed by the keyboard?
0
 
LVL 42

Accepted Solution

by:
David S. earned 100 total points
ID: 37779782
Yes, the click event will fire even if the keyboard is used to select the radio button instead of the mouse.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

919 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

21 Experts available now in Live!

Get 1:1 Help Now