Last active
December 26, 2015 19:19
-
-
Save rbk/7200405 to your computer and use it in GitHub Desktop.
This is a placeholder workaround for text inputs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') ); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't use this. It doesn't work right