Posted By

keith on 05/05/09


Tagged

form input jquery viget


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Flocke
vali29


Toggle INPUT value on focus


 / Published in: jQuery
 

The markup would look like this: <input class="swap-value" type="text" value="Search"/ >

  1. swapValue = [];
  2. $(".swap-value").each(function(i){
  3. swapValue[i] = $(this).val();
  4. $(this).focus(function(){
  5. if ($(this).val() == swapValue[i]) {
  6. $(this).val("");
  7. }
  8. $(this).addClass("focus");
  9. }).blur(function(){
  10. if ($.trim($(this).val()) == "") {
  11. $(this).val(swapValue[i]);
  12. $(this).removeClass("focus");
  13. }
  14. });
  15. });

Report this snippet  

You need to login to post a comment.