Advertisement
Guest User

label and input

a guest
Oct 25th, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     $('label').each(function() {
  3.         var label = $(this);
  4.         var element = $('#'+ label.attr('for'));
  5.         var position = element.position();
  6.         label.css('position', 'absolute').css('left', position.left + 10).css('top', position.top - 8);
  7.  
  8.         element.focus(function() {
  9.             label.fadeOut(100);
  10.         });
  11.  
  12.         element.blur(function() {
  13.             if (element.val().length == 0) {
  14.                 label.fadeIn(100);
  15.             }
  16.         });
  17.     });
  18. });
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement