Return to Snippet

Revision: 13760
at May 5, 2009 16:11 by keith


Initial Code
swapValue = [];
$(".swap-value").each(function(i){
   swapValue[i] = $(this).val();
   $(this).focus(function(){
      if ($(this).val() == swapValue[i]) {
         $(this).val("");
      }
      $(this).addClass("focus");
   }).blur(function(){
      if ($.trim($(this).val()) == "") {
         $(this).val(swapValue[i]);
	 $(this).removeClass("focus");
      }
   });
});

Initial URL

                                

Initial Description
The markup would look like this:
<code> &lt;input class="swap-value" type="text" value="Search"/ &gt;</code>

Initial Title
Toggle INPUT value on focus

Initial Tags
form, jquery

Initial Language
jQuery