javascript - Stick label within input field that does not change when typed. (No placeholder). HTML/JS/JQuery -


please see screenshot below, on left side i'm getting , on right side want achieve without using plugins or html5 attributes

enter image description here

the way left side of screen happens have 2 input fields out of 1 has value username: , other 1 hidden. when focus username: input field, field gets hidden , new field becomes visible. on blurr event vice-verse happens.

js code:

$(document).on('focus', '#login .placeholder', function() {     var inel = $('#user_name');     if (inel && ! inel.is(':visible')) {        $(this).hide();        inel.show().focus();     } });  $(document).on('blur', '#user_name', function() {     if ($(this).val().length <= 0) {         var placeholderelement = $('#login .placeholder');         placeholderelement.show();         $(this).hide();     } }); 

http://jsbin.com/emasuj/1/edit

<label>   username:   <input type="text" />     </label> 

css:

input{   border:none;   background:#eee; } label{   color:#777;   padding:10px;   background:#eee;   border-radius:5px; } 

if want change bg colors on focus here example how bit of jq:
http://jsbin.com/emasuj/2/edit


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -