Skip to content

Instantly share code, notes, and snippets.

@carlito
Created April 3, 2014 08:23
Show Gist options
  • Select an option

  • Save carlito/9950521 to your computer and use it in GitHub Desktop.

Select an option

Save carlito/9950521 to your computer and use it in GitHub Desktop.
Input value toggle with jQuery
$.each($('input'), function(){
var v = $(this).val();
$(this).focus(function(){
var current_v = $(this).val();
if(current_v==v) {
$(this)
.val('')
.addClass('active');
}
});
$(this).blur(function(){
var current_v = $(this).val();
if(current_v=='') {
$(this).val(v);
$(this).removeClass('active');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment