Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
How to add a sub parent class inside the parent class using Jquery

Hi I want to add a sub parent class to my parent class using jQuery.

Previously I've tried this:

$('.my-parent').wrap('<div class="my-sub-parent"></div>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="my-parent">
    <div class="child-items">1</div>
    <div class="child-items">2</div>
    <div class="child-items">3</div>
    <div class="child-items">4</div>
</div>

But this one inserts the class outside of my parent, not inside.

What I want to achieve is like this html structure:

<div class="my-parent">
    <div class="my-sub-parent">
        <div class="child-items"></div>
        <div class="child-items"></div>
        <div class="child-items"></div>
        <div class="child-items"></div>
    </div>
</div>

Is this achievable? Any help would be great. Thanks.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need wrapInner function.

$('.my-parent').wrapInner('<div class="my-sub-parent"></div>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="my-parent">
    <div class="child-items">1</div>
    <div class="child-items">2</div>
    <div class="child-items">3</div>
    <div class="child-items">4</div>
</div>

For more resources.

https://api.jquery.com/wrapinner/

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!