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

  • SEARCH
  • Home
  • 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 6546077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:39:50+00:00 2026-05-25T11:39:50+00:00

On page load, I want to wrap the header span with div and move

  • 0

On page load, I want to wrap the header span with div and move it into the front of related body div.
ie, move hApplicant1 span into the front of tabApplicant1 div, etc.

How do I write jQuery to accomplish this? thanks !

Given:

<div>
            <div id="header">
                <span id="hDummy"></span>
                <span id="hApplicant1">James Smith</span>
                <span id="hApplicant2">John Doe</span>
                <span id="hApplicant3"></span>
                <span id="hApplicant4"></span>
            </div>
            <div id="body">
                <div id="tabApplicant1">...</div>
                <div id="tabApplicant2">...</div>
            </div>
</div>
<div>
            <div id="header2">
                <span id="h2Dummy"></span>
                <span id="h2Applicant1">Black Smith</span>
                <span id="h2Applicant2">Shoe Maker</span>
                <span id="h2Applicant3"></span>
                <span id="h2Applicant4"></span>
            </div>
            <div id="body2">
                <div id="tab2Applicant1">...</div>
                <div id="tab2Applicant2">...</div>
            </div>
</div>

the result should be like this:

<div>
            <div id="header">
                <span id="hDummy"></span>
                <span id="hApplicant3"></span>
                <span id="hApplicant4"></span>
            </div>
            <div id="body">
                <div><span id="hApplicant1">James Smith</span></div>
                <div id="tabApplicant1">...</div>
                <div><span id="hApplicant2">John Doe</span><div>
                <div id="tabApplicant2">...</div>
            </div>
</div>
<div>
            <div id="header2">
                <span id="h2Dummy"></span>
                <span id="h2Applicant3"></span>
                <span id="h2Applicant4"></span>
            </div>
            <div id="body2">
                <div><span id="h2Applicant1">Black Smith</span></div>
                <div id="tab2Applicant1">...</div>
                <div><span id="h2Applicant2">Shoe Maker</span><div>
                <div id="tab2Applicant2">...</div>
            </div>
</div>
  • 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-05-25T11:39:51+00:00Added an answer on May 25, 2026 at 11:39 am
    var $bodyDiv = $('#body');
    
    $('#header span[id^=hApplicant]').each(function(){
        $bodyDiv.find('div[id=' + $(this).attr('id').replace('h', 'tab') + ']').before( $(this).wrap('<div />').parent() );
    });
    

    And here’s the fiddle: http://jsfiddle.net/Hw2Gz/

    This can be further simplified (and optimized), but it should get you started on the right track.


    EDIT:

    This can be repeated:

    var $bodyDiv = $('#body'),
        $bodyDiv2 = $('#body2');
    
    $('#header span[id^=hApplicant]').each(function(){
        $bodyDiv.find('div[id=' + $(this).attr('id').replace('h', 'tab') + ']').before( $(this).wrap('<div />').parent() );
    });
    
    $('#header2 span[id^=h2Applicant]').each(function(){
        $bodyDiv2.find('div[id=' + $(this).attr('id').replace('h', 'tab') + ']').before( $(this).wrap('<div />').parent() );
    });
    

    http://jsfiddle.net/Hw2Gz/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to move (on page load) the <span>votes</span> part at the bottom and
Upon page load I want to move the cursor to a particular field. No
I am building a blog type page, and I want to load items into
I want to have a page loaded into a div and while the page
On page load I want a div to be hidden. I attached an alert
My HTML markup looks like that <html> <body> <div id=loading><img src=core/design/img/load/load.gif /></div> <div id=wrap></div>
I want this div to load instantly on page load (or thereabouts) and then
Hi I want to set opacity for a form in page load. I try
I want to fake a simple animation on page load by sequentially revealing several
I want to load the data into session so that when the next button

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.