Skip to content

Instantly share code, notes, and snippets.

@rbk
Last active December 26, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbk/7200405 to your computer and use it in GitHub Desktop.
Save rbk/7200405 to your computer and use it in GitHub Desktop.
This is a placeholder workaround for text inputs
jQuery(document).ready(function($){
$('input[type=text]').each(function(){
$(this).val( $(this).attr('placeholder') );
});
$('input[type=text]').keyup(function(){
var placeholder = $(this).attr('placeholder');
var regex = new RegExp(placeholder);
$(this).val( $(this).val().replace(regex, ''))
if( $(this).val() == '' ){
$(this).val( $(this).attr('placeholder') );
}
})
$('input[type=text]').focus(function(){
if( $(this).val() == $(this).attr('placeholder') );
$(this).val( $(this).attr('placeholder') );
})
});
@rbk
Copy link
Author

rbk commented Oct 28, 2013

Don't use this. It doesn't work right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment