Harry Sarshogh
Harry Sarshogh

Reputation: 2197

Swap two fieldsets by jQuery

I have Div tage and within have 2 fieldset tags. I need after checking conditions in document ready event, call function for swap them .I mean fieldset 2 come up fieldset1 .

please note this sample :

      <div id='InformationDiv'>

         <fieldset id='fieldset1'>
              ...
              ...
         </fieldset>

         <fieldset id='fieldset2'>
              ...
              ...
         </fieldset>
      </div>

Upvotes: 1

Views: 105

Answers (2)

Deepak Ingole
Deepak Ingole

Reputation: 15752

Simply use,

$(function() {
    // check for condition

    // swap elements
    $("#fieldset1").before($("#fieldset2")); //put fieldset1 before fieldsset2
    //Or
    $("#fieldset2").before($("#fieldset1")); //put fieldset2 before fieldsset1
});

Similarly you can try using .after(), .insertBefore(), .insertAfter()

Upvotes: 1

absqueued
absqueued

Reputation: 3063

You can achieve with these snippets:

    $("#InformationDiv fieldset:first").insertAfter($("#InformationDiv fieldset:last"));

Above script will work always even if you want to make swap many times.

Upvotes: 3

Related Questions