softcode softcode - 8 months ago 47
Javascript Question

jQuery before() outputting as string rather than HTML

I'm trying to inject some HTML before an input on Gravity Forms using some simple jQuery.

Here is my code:

var formInputs = jQuery( "form li input" )

formInputs.each(function( index ) {
this.before('<h1>Hello, world!</h1>');
});


Here is what it looks like on each input

enter image description here

Is there some form of conflict with Gravity Forms?

EDIT: I tried replacing

this.before('<h1>Hello, world!</h1>');


with

this.before(jQuery('<h1>Hello, world!</h1>'));


and instead I get jQuery object

enter image description here

Answer

Have you tried this?

jQuery('<h1>Hello World!</h1>').insertBefore(this);

https://jsfiddle.net/r181ohtj/