I need to know if user clicked to already checked radio or he made a new choice. Now I detect it via "focus", "click" and "change" events combination (store old value in "focus", and compare it with current in "click" or "change" to detect and handle click to already checked radio).
Just to clarify: I cant store previous state in click handler, because I could not get the the initial state here; or "focus+click" or "load+(prev)click+click";
But it looks like a hack for me, and I assume that there is a more straight way to do this using built-in jquery features, using just one event handler. Is there something like this?
Thanks in advance!
Use mousedown
as @Bukent Vural suggests.
Get the current value before change with $('input[name=test]:checked').val();
,
where 'test' is the name of your radio inputs.
Take a look at this JSFiddle.
EDIT
If you want to detect label clicks as well, a second event handler needs to be added:
$('label').click(function() {
labelID = $(this).attr('for');
$('#'+labelID).trigger('mousedown');
});
Check the updated JSFiddle.