Created
June 15, 2011 21:04
-
-
Save citrus/1028100 to your computer and use it in GitHub Desktop.
jQuery Textfield-Value Labels
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
// jQuery Textfield Labels | |
// Valabel == Value + Label | |
// by Spencer Steffen | |
// Citrus Media Group | |
// [email protected] | |
;(function($) { | |
var version = '0.1.0'; | |
$.fn.valabel = function() { | |
var args = arguments; | |
return this.each(function() { | |
var options = this.options = $.extend(false, this.options || $.fn.valabel.defaults, (args[0] && args[0].constructor == Object ? args[0] : {})); | |
var self = this.self || $(this).addClass(options.class_name); | |
var text = this.text || options.text || self.val(); | |
if (self.val() != text) { | |
self.val(text); | |
} | |
self.focus(function() { | |
if (self.val() == text) { | |
self.val("").removeClass(options.class_name); | |
} | |
}).blur(function() { | |
if (self.val() == "") { | |
self.val(text).addClass(options.class_name); | |
} | |
}); | |
return this; | |
}); | |
}; | |
$.fn.valabel.defaults = { | |
class_name: 'light', | |
text: null | |
}; | |
})(jQuery); |
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() { | |
$("#keywords, #search_keywords").valabel(); | |
$("#email").valabel({ class_name: "blur", :text => "Enter your email" }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment