jQuery(document).ready(function ($) { var selectors = [ 'input[type=text]', 'input[type=email]', 'input[type=url]', 'input[type=tel]', 'input[type=number]', 'input[type=date]', 'input[type=file]', 'textarea', 'select' ]; var onFilled = function (ev) { var el = $(ev.target); if (el.val() && !el.hasClass('filled')) { el.addClass('filled'); } else { el.removeClass('filled'); } }; var form = $('.wpcf7-form'); $(selectors.join(), form) .on('focus', $.proxy(onFilled, this)) .on('blur', $.proxy(onFilled, this)); });