Skip to content

Instantly share code, notes, and snippets.

@d3ep4k
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save d3ep4k/6ea77f2bf3175b1897b6 to your computer and use it in GitHub Desktop.

Select an option

Save d3ep4k/6ea77f2bf3175b1897b6 to your computer and use it in GitHub Desktop.
<!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