March 29, 2016

Gravity form: Adding a placeholder by jquery, Get rid of plugins

Gravity form: adding a placeholder by jquery script.

To make it smoother and lightweight I coded a script to get the label and place it to all gravity form input field in your page as a placeholder.

jQuery( document ).ready(function() {
var gfields = jQuery(“.gfield”);
gfields.each(function() {
var obj= jQuery(this);
obj.find(‘.gfield_required’).remove();
var glabel = obj.find(‘.gfield_label’).html();
obj.find(‘input’).attr(‘placeholder’,glabel);
//obj.find(‘textarea’).attr(‘placeholder’,glabel.text());

});
});

Please replace the jQuery by $ if you see any conflicts

You may also like...

Leave a Reply