Skip to content

Instantly share code, notes, and snippets.

@Beneboe
Created February 24, 2013 15:00
Show Gist options
  • Save Beneboe/5024134 to your computer and use it in GitHub Desktop.
Save Beneboe/5024134 to your computer and use it in GitHub Desktop.
makes labels go inside an input tag
<form action="/message">
<p>
<label for="user_tel">Telephone:</label>
<input type="text" id="user_tel"><br />
</p>
<p>
<label for="user_msg">Message:</label>
<textarea name="" id="user_msg" cols="30" rows="10">
</textarea><br />
</p>
<input type="submit" value="Absenden">
</form>
$('label').addClass('labelinside');
$('label').closest('p').find('input, textarea')
.on('focus', function() {
$(this).prev().animate({'opacity': '0.5'}, 100);
$(this).on('keydown', function() {
$(this).prev().hide();
});
})
.on('blur', function() {
$(this).prev().animate({'opacity': '1'}, 100);
if($(this).val() === '') {
$(this).prev().show();
}
})
.labelinside {
position: absolute;
padding: <some padding>;
color: #000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment