Skip to content

Instantly share code, notes, and snippets.

@emayk
Created March 13, 2012 07:10
Show Gist options
  • Save emayk/2027378 to your computer and use it in GitHub Desktop.
Save emayk/2027378 to your computer and use it in GitHub Desktop.
JS : Snippet Query Focus on input text
$(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&quot.each(function (i) {
$(this).next("input&quot.attr("value",$(this).html()+"..."
$(this).hide();
});
$("#signup input&quot.focus(function() {
if($(this).prev("label&quot.html()+"..." == this.value){
$(this).addClass("focus&quot.setCursorPosition(0);
}
});
$("#signup input&quot.keypress(function() {
if($(this).prev("label&quot.html()+"..." == this.value){
this.value = "";
$(this).removeClass("focus&quot.addClass("typing"
}
});
$("#signup input&quot.blur(function() {
$(this).removeClass("focus&quot.removeClass("typing"
if(this.value == "&quot{
this.value = $(this).prev("label&quot.html()+"...";
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment