Last active
August 29, 2015 14:27
-
-
Save d3ep4k/6ea77f2bf3175b1897b6 to your computer and use it in GitHub Desktop.
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> | |
| <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
| <meta charset="utf-8"> | |
| <style> | |
| .holder{ | |
| color:grey; | |
| margin-left: 2px; | |
| margin-top:2px; | |
| position:absolute; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <input type="text" name="name" placeholder="Enter Name" autofocus="autofocus" /> | |
| <script src="jquery.min.js"></script> | |
| <script> | |
| var $input = $('input') | |
| $('[autofocus]').focus(); | |
| $('body').append('<span class="holder">'+$input.attr('placeholder')+'</span>'); | |
| $input.attr('placeholder','') | |
| $('.holder').css('top',$input.position().top) | |
| $('.holder').css('left',$input.position().top) | |
| $input.on('keydown', function(e) { | |
| var val = $input.val(); | |
| if (val.length == 0 && e.which != 0) { | |
| $('.holder').hide(); | |
| } | |
| }) | |
| $input.on('keyup', function(e) { | |
| var val = $input.val(); | |
| if (val.length == 0 && e.which != 0) { | |
| $('.holder').show(); | |
| } | |
| }); | |
| </script> | |
| </body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment