Skip to content

Instantly share code, notes, and snippets.

@atrandafir
Last active December 19, 2015 17:29
Show Gist options
  • Save atrandafir/5991483 to your computer and use it in GitHub Desktop.
Save atrandafir/5991483 to your computer and use it in GitHub Desktop.
Blur a readonly text field because by default jQuery.blur() does not do it.
(function($) {
$.fn.readOnlyBlur = function() {
return this.each(function() {
if ($(this).is('input')) {
if ($(this).is('[readonly]')) {
var readonly_var=$(this).attr("readonly");
$(this).removeAttr("readonly");
$(this).blur();
$(this).attr("readonly",readonly_var);
} else {
$(this).blur();
}
} else {
$(this).blur();
}
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment