imjp
imjp

Reputation: 6695

Using JavaScript/jQuery to move input field position in a form

I have the following form on my website

input a
input b
input c


Is it possible to have the following done using jQuery?

input a
input c
input b


Keep in mind that the form still needs to collect the data correctly.

Please advise.

Upvotes: 0

Views: 8208

Answers (1)

David Thomas
David Thomas

Reputation: 253318

Yes, that's possible, it's easier, albeit the same technique, with ids but if you just know which one you want to move, then:

$('input:text:nth-child(3)').insertAfter($('input:text:nth-child(1)'));

JS Fiddle demo

JS Fiddle of id-based approach (generously offered by Vega).

Or, similarly:

$('input:text:nth-child(3)').appendTo($('input:text:nth-child(1)').parent());

JS Fiddle demo.

JS Fiddle demo of id-based approach.

References:

Upvotes: 5

Related Questions