/ Published in: jQuery
Focus and keypress events determine when to hide, show, or dim a label.
Use in tandem with the following HTML/CSS:
HTML
----
<li>
First Name
</li>
CSS
----
li {
position: relative;
}
label {
position: absolute;
top: 1px;
left: 1px;
cursor: text;
}
Use in tandem with the following HTML/CSS:
HTML
----
<li>
First Name
</li>
CSS
----
li {
position: relative;
}
label {
position: absolute;
top: 1px;
left: 1px;
cursor: text;
}
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function() { $('input[type=text]').focusin(function () { $(this).prev('label').css('color','#999'); }); $('input[type=text]').focusout(function () { $(this).prev('label').css('color','#111'); }); $('input[type=text]').keydown(function () { if($(this).attr('value') == '') { $(this).prev('label').hide(); } }); $('input[type=text]').keyup(function () { if ($(this).attr('value') == '') { $(this).prev('label').show(); $(this).prev('label').css('color','#999'); } }); });
URL: http://mikemetcalf.com/share/overlabel