Solved

jQuery: Fire only once with multiple binds

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i get the length? 7 32
How to make a moving character 3 56
Passport Expiry 3 44
Mouse event to control image and transparency. 4 19
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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

776 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