I'm dying to solve my problem with autogenerated input in a span. I'm using the Wordpress plugin Contact Form 7 on my website and I want so animate the label while the user in using the input field.
When the input-field is on focus or something is typed in it, the class active should appear in the div with the class "grid-3".
I tried to get the javascript myself but it doesnt works:
$('.wpcf7-form-control-wrap').each(function() {
//console.log($(this));
$(this).on('focus', function() {
$(this).parent().parent().addClass('active');
});
$(this).on('blur', function() {
if ($(this).val().length == 0) {
$(this).parent().parent().removeClass('active');
}
});
if ($(this).val() != '') $(this).parent('.grid-3').addClass('active');
});
The HTML:
<div class="grid-3">
<label for="schenkel2">Schenkel 2 in mm</label>
<span class="wpcf7-form-control-wrap schenkel2">
<input type="text" name="schenkel2" value="" size="40" class="wpcf7-form-control wpcf7-text" id="schenkel2" aria-invalid="false">
</span>
</div>
Do you use CSS for this ? I think u can achieve it easily with CSS3
above first one is to add the default styles for a text area and second CSS is to get the on focus effect add the inputHover class into your Input tag and check