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 8487991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:24:23+00:00 2026-06-10T21:24:23+00:00

I have a question. How would i iterate through each h2 in their div,

  • 0

I have a question.

How would i iterate through each h2 in their div, grab their text value and appending that to the other set of divs in the order that they appear on the other side?

i could use eq or something and go through each one but this isn’t ideal as the number of divs at any given time could be more or less and i’ll only have to go back and adjust the js to adjust for the number of divs.

There is no js i’ve done yet in this example just because i’m not sure how to approach this.

Any help is appreciated.

Fiddle Example

Thanks

  • 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-10T21:24:24+00:00Added an answer on June 10, 2026 at 9:24 pm

    I think using .eq is your only choice, but it does not make your code inflexible:

    var $divs = $('.wrap-two div.item');
    
    $('.wrap h2').each(function(index) {
        $divs.eq(index).text($(this).text());
    });
    
    // or alternatively:
    
    var $h2s = $('.wrap h2');
    
    $('.wrap-two div.item').text(function(index) {
        return $h2s.eq(index).text();
    });
    

    DEMO

    Additional divs will be just left empty and too few divs are not a problem either. .eq will always return a jQuery object, even if an element with that index does not exist. The call to .text will then just be silently ignored.

    Or do you want to always have as many divs as h2s?

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

Sidebar

Related Questions

I have referred to the following question at: Using foreach loop to iterate through
I thought this question would have already existed on SO, but then I couldn't
I have question concerning a function I created. I would like to show the
I have a question. How would I build a method (dataCapture()) to collect the
I have a question which is described below: What problems would arise for testing
I have a basic question. I would like to make running Arc.py several times
I have a general question. I would like to have a window containing some
I have the entire question list saved in Microsoft excel spreadsheet. I would like
This is hopefully a simple question: I have an OpenGL texture and would like
Just a knowledge question which I would like to ask: For example, I have

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.