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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:51:28+00:00 2026-05-13T18:51:28+00:00

Ok I have a page setup that looks like this: <div class=parent>Content here</div> I

  • 0

Ok I have a page setup that looks like this:

<div class="parent">Content here</div>

I want to grab each div with the class ‘parent’, and make it look like this:

<div class="parent">
<div class="child"></div>
Content Here
<div class="child">
</div>

I know how to loop through each div with the class ‘parent’, except I dont know how to add the ‘child’ div before and after the content. Help?

  • 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-13T18:51:28+00:00Added an answer on May 13, 2026 at 6:51 pm

    In browsers that support getElementsByClassName, you can do this:

    var parents = document.getElementsByClassName("parent");
    for (i=0; i<parents.length; i++){
      var child = document.createElement("div");
      child.setAttribute("class","child");
      parents[i].insertBefore(child, parents[i].firstChild);
      parents[i].appendChild(child);
    }
    

    getElementsByClassName is supported by Chrome, Firefox 3+, as well as recent versions of Opera, and Safari. (see http://www.quirksmode.org/dom/w3c_core.html#fivemethods). Unfortunately it is not currently supported by any version of Internet Explorer.

    Of course, you can write your own version of getElementsByClassName that works in IE. (Basically it just needs to cycle through each element and add it to the collection if its class attribute matches the specified value.) Or you can get someone else to write it for you, either by using code you find online or just using a framework as prodigitalson suggests.

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

Sidebar

Related Questions

Here's the problem: 1.) We have page here... www.blah.com/mypage.html 2.) That page requests a
I have a page where there is a column and a content div, somewhat
I have a setup that requires a header div and a footer div to
Setup: I have an HTML page with a fieldset element. The background color of
I have a page that is generated which inserts an HTML comment near the
I have a page with a Google Maps mashup that has pushpins that are
I have a page that uses $(id).show(highlight, {}, 2000); to highlight an element when
My issue is i have QUERY_STRING enabled in my codeigniter setup so that links
I have a web page that uses the QuickTime plugin to display a 360-degree
I have a custom error page set up for my application: <customErrors mode=On defaultRedirect=~/errors/GeneralError.aspx

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.