Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8509367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:24:55+00:00 2026-06-11T03:24:55+00:00

I have some inputs in divs. It seems like below: <div name=emailInput> <input type=text

  • 0

I have some inputs in divs. It seems like below:

<div name="emailInput">
      <input type="text" name="email_1" /></div>
<div name="phoneInput">
      <input type="text" name="phone_number_1"   /></div>

<div name="emailInput">
      <input type="text" name="email_2"   /></div>
<div name="phoneInput">
      <input type="text" name="phone_number_2" /></div>

<div name="emailInput">
      <input type="text" name="email_3"  /></div>
<div name="phoneInput">
      <input type="text" name="phone_number_3" /></div>

But in some cases, I need to change the order of inputs. Specifically, I want to swap emails and phones locations. Result must be:

<div name="emailInput">
      <input type="text" name="phone_number_1" /></div>
<div name="phoneInput">
      <input type="text" name="email_1"   /></div>

<div name="emailInput">
      <input type="text" name="phone_number_2"   /></div>
<div name="phoneInput">
      <input type="text" name="email_2" /></div>

<div name="emailInput">
      <input type="text" name="phone_number_3"  /></div>
<div name="phoneInput">
      <input type="text" name="email_3" /></div>

To achieve my goal I write jquery code:

$('div[name^= emailInput]').insertBefore('div[name^= phoneInput]');

This code swapped whole phoneInputs divs before each emailInputs divs. How can I swap divs one by one? (The count of the inputs is unkown)

Also,

  $('input[name^= email]').insertBefore('input[name^= phone_number]');

doesnt work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:24:57+00:00Added an answer on June 11, 2026 at 3:24 am

    Try this:

    $('input[name^="phone_number"]').each(function(){
       var $this = $(this);
       var $prev = $this.parent().prev()
       $prev.find('input').insertAfter($this);
       $this.appendTo($prev)    
    })
    

    http://jsfiddle.net/PnT4Q/1/

    You can also change the position of the div tags.

    $('div[name="phoneInput"]').each(function(){
      var $this = $(this);
      $this.insertBefore($this.prev())   
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenerio: I have some divs populated through foreach loop like below <div id=div1><input type=hidden
I have some hidden inputs like this <input name=exam.normals[1].blahblah ..../> I would like somehow
I toggle a div using something like this - <input type=radio name=myRadio value=myDiv_1 />MyDiv
I have some DIVs inserted by jQuery. The structure is like this: <div class=preview_images
I'd like to have some hidden inputs on View A.aspx and pass the values
I can't use EditorFor because my inputs have some other attributes like readonly ,
I have some input like this: aaaaa bbb \n cccccc\n ddddd \neeee And I
I have an HTML form consisting of some text-inputs. I'm using jqTransform to prettify
I have a some html that looks like this <div id=main> <div id=sub_main_1 class=sub_main>
I some divs with forms inside of them and i do have inputs with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.