Solved

jQuery: Fire only once with multiple binds

Posted on 2012-03-28
4
420 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

856 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