Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Last active December 18, 2015 18:39
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 mhkeller/5827111 to your computer and use it in GitHub Desktop.
Save mhkeller/5827111 to your computer and use it in GitHub Desktop.
Create blurring of textfields for non-skinny pants browsers that don't know from 'placeholder="my pants are skinny"'
function makeTextfieldsPlaceholderable(){
/* Clears textfields from helper text on click */
var $textfield = $('.placeholder-textfield');
$textfield.focus(function(srcc){
if ($(this).val() == $(this)[0].title){
$(this).removeClass("placeholder-textfield-active");
$(this).val("");
}
});
$textfield.blur(function(){
if ($(this).val() == ""){
$(this).addClass("placeholder-textfield-active");
$(this).val($(this)[0].title);
}
});
$textfield.blur();
}
makeTextfieldsPlaceholderable();
<!-- Your label will take its 'title' as its placeholder text -->
<input class="placeholder-textfield" type="textfield" title="Search...">
.placeholder-textfield{
color:black;
}
.placeholder-textfield-active {
color: #848484;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment