Published on Tuesday, September 13, 2011 by Jason in jQuery
This code allows you to easily set the focus and blur CSS class on form elements using jQuery.
// Set focus and blur CSS class for the following fields and field types
$("input, textarea, select").addClass("idle");
$("input, textarea, select").focus(function(){
$(this).addClass("activeField").removeClass("idle");
}).blur(function(){
$(this).removeClass("activeField").addClass("idle");
});
Published on Tuesday, September 13, 2011 by Jason in jQuery
This code is an easy way to allow radio buttons to be deselected using jQuery. So when a radio button is selected just click it again to deselect.
// Allow radio buttons to be deselected
var radioChecked;
$('input[type=radio]').bind('mousedown', function() {
radioChecked = $(this).attr('checked');
});
$('input[type=radio]').bind('click', function() {
if (radioChecked) {
$(this).attr('checked', false);
} else {
$(this).attr('checked', true);
}
});
Published on Tuesday, September 13, 2011 by Jason in jQuery
This code is an easy way to set the tab index of your form elements using jQuery.
// Set tab index on form elements
var tabindex = 1;
$("input, textarea, select").each(function(){
if (this.type != "hidden") {
var $input = $(this);
$input.attr("tabindex", tabindex);
tabindex++;
}
});