Solved

jQuery: Fire only once with multiple binds

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

747 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