Created
November 3, 2011 16:16
-
-
Save ajaswa/1336927 to your computer and use it in GitHub Desktop.
input label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype> | |
| <html> | |
| <head> | |
| <link href="input-label.css" rel='stylesheet' type='text/css' /> | |
| <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script> | |
| <script src="input-label.js"></script> | |
| </head> | |
| <body> | |
| <form> | |
| <fieldset> | |
| <span> | |
| <label class='infield' for='field'>label</label> | |
| <input id='field' /> | |
| </span> | |
| </fieldset> | |
| </form> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| form { | |
| margin:10px 0px; | |
| } | |
| form fieldset { | |
| margin-bottom:20px; | |
| } | |
| form fieldset span { | |
| margin:0 0 5px; | |
| display:block; | |
| position:relative; | |
| } | |
| form fieldset span label { | |
| color:#ccc; | |
| font-size:116%; | |
| display:block; | |
| position:absolute; | |
| top:6px; | |
| left:5px; | |
| } | |
| form fieldset span input { | |
| background:#fff; | |
| padding:4px; | |
| font-size:116%; | |
| color:#444; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function (){ | |
| var inputs = $('form input'); | |
| inputs.each(function(){ | |
| if ( $(this).val() !== '') $(this).siblings('label').fadeOut() | |
| }).on('focus', function(){ | |
| $(this).siblings('label').fadeOut() | |
| }).on('blur', function(){ | |
| if ( $(this).val() === '') $(this).siblings('label').fadeIn() | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment