softcode softcode - 1 year ago 77
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>');


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

and instead I get jQuery object

enter image description here

Answer Source

Have you tried this?

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download