Clear form input on focus


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

Clear text input when the user selects it (on focus)


Copy this code and paste it in your HTML
  1. $.fn.search=function(){return this.focus(function(){if(this.value==this.defaultValue){this.value=""}}).blur(function(){if(!this.value.length){this.value=this.defaultValue}})}
  2. $("input, textarea").search();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.