Created
March 13, 2012 07:10
-
-
Save emayk/2027378 to your computer and use it in GitHub Desktop.
JS : Snippet Query Focus on input text
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
$(document).ready(function() { | |
$.fn.setCursorPosition = function(pos) { | |
if ($(this).get(0).setSelectionRange) { | |
$(this).get(0).setSelectionRange(pos, pos); | |
} else if ($(this).get(0).createTextRange) { | |
var range = $(this).get(0).createTextRange(); | |
range.collapse(true); | |
range.moveEnd('character', pos); | |
range.moveStart('character', pos); | |
range.select(); | |
} | |
} | |
$("#signup label".each(function (i) { | |
$(this).next("input".attr("value",$(this).html()+"..." | |
$(this).hide(); | |
}); | |
$("#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