Skip to content

Instantly share code, notes, and snippets.

@Narga
Created June 7, 2012 02:46
Show Gist options
  • Save Narga/2886236 to your computer and use it in GitHub Desktop.
Save Narga/2886236 to your computer and use it in GitHub Desktop.
jQuery - handle the CSS classes in inline label form
//http://www.narga.net/making-awesome-forms-inline-labels-with-jquery
$("#signup input").focus(function() {
if($(this).prev("label").html()+"..." == this.value){
$(this).addClass("focus").setCursorPosition(0);
}
});
$("#signup input").keypress(function() {
if($(this).prev("label").html()+"..." == this.value){
this.value = "";
$(this).removeClass("focus").addClass("typing"
}
});
$("#signup input").blur(function() {
$(this).removeClass("focus").removeClass("typing"
if(this.value == ""){
this.value = $(this).prev("label").html()+"...";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment