Skip to content

Instantly share code, notes, and snippets.

@jonkarna
Created March 26, 2009 21:12
Show Gist options
  • Save jonkarna/86342 to your computer and use it in GitHub Desktop.
Save jonkarna/86342 to your computer and use it in GitHub Desktop.
jQuery: Automatically set value of input based on title of input
$("input[type=text][title]").each(function() {
$(this).val($(this).attr("title"));
if($.trim($(this).val()) == "")
$(this).val($(this).attr("title"));
$(this).focus(function() {
if($(this).val() == $(this).attr("title"))
$(this).val("");
}).blur(function() {
if($.trim($(this).val()) == "")
$(this).val($(this).attr("title"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment