html - Jquery remove labels from contact form on focus -
i need contact form. i'm trying remove labels automatically when user clicks in box, can't seem figure out how.
this html
<div class="six columns"> <form> <div class="row"> <div class="six columns"> <label class="gfield_label" for="name" style="display: block;">name<span class="gfield_required">*</span> </label> <input type="text" id="name" required class="mobile-four" /> </div> <div class="six columns"> <label class="gfield_label" for="name" style="display: block;">company</label> <input type="text" id="name" required class="mobile-four" /> </div> </div> <div class="row"> <div class="six columns mobile-four"> <label class="gfield_label" for="email" style="display: block;">email<span class="gfield_required">*</span> </label> <input type="email" class="mobile-four" id="email" required /> </div> <div class="six columns mobile-four"> <label class="gfield_label" for="phone" style="display: block;">phone<span class="gfield_required">*</span> </label> <input type="phone" class="mobile-four" id="phone" required /> </div> </div> <div class="row"> <div class="twelve columns mobile-four"> <label class="gfield_label" for="message" style="display: block;">message<span class="gfield_required">*</span> </label> <textarea id="message" cols="30" rows="3"></textarea> </div> <div class="three columns centered"> <button id="contact-submit-btn" class="btn btn-block btn-danger">contact now!</button> </div> </div> </form> </div>
and js have tried far. nothing seems work.
$('input, textarea').focus(); $(this).prev('label').hide(); }); $('.gfield_label').focus(function () { $('label.mobile-four[for="' + $(this)[0].id + '"]').hide(); }); $('.gfield_label').each(function () { 2 var elem = $(this); 3 $('label[for="' + $(this).attr('id') + '"]').click(function () { 4 elem.focus(); 5 }); 6 if ($(this).val() != '') { 7 $('label[for="' + $(this).attr('id') + '"]').hide(); 8 } 9 }).focus(function () { 10 $('label[for="' + $(this)[0].id + '"]').hide(); 11 }).blur(function () { 12 if ($(this).val() == '') { 13 $('label[for="' + $(this)[0].id + '"]').show(); 14 } 15 }).change(function () { 16 if ($(this).val() != '') { 17 $('label[for="' + $(this)[0].id + '"]').hide(); 18 } 19 })
it great if help. page @ beta.harbordev.com/contact.html
thanks much
update!!!!!
$(function() { $('input, textarea').on('focus blur', function () { $(this).prev().toggle(); }); });
this suggestion kind fo worked. it's live on website now, somehow message field (textarea) disappears whatever else selected , gone when nothing selected. know why?
$(function() { $('input, textarea').on('focus blur', function () { $(this).prev().toggle(); }); });
Comments
Post a Comment