Last active
December 18, 2015 18:39
-
-
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"'
This file contains 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
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(); |
This file contains 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
<!-- Your label will take its 'title' as its placeholder text --> | |
<input class="placeholder-textfield" type="textfield" title="Search..."> |
This file contains 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
.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