Textbox inside-label replace


/ Published in: jQuery
Save to your folder(s)

Replaces the pre-defined text of a textbox (e.g. the purpose of the textbox) when the textbox gets focussed, and resets the text if it blurs when empty


Copy this code and paste it in your HTML
  1. <input type="text" value="Name" rel="Name" class="replace" />
  2.  
  3. $(".replace")
  4. .focus(function(){
  5. if ($(this).val() === $(this).attr("rel")) {
  6. $(this).val("").css("color", "#000000");
  7. }
  8. })
  9. .blur(function(){
  10. if ($(this).val() === "") {
  11. $(this).val($(this).attr("rel")).css("color", "#5e6a72");
  12. }
  13. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.