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

102
Views
How to use JQuery to Wrap a specific list of div children

I am doing AB testing in google optimize. I need to wrap div from number 5 to 10 but I have not been able to do it:

<div class="container active" data-order="1">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<button>11</button>
<div>12</div>
</div>

I am using this code to do it but it start wrapping from div number one but I want to start with div number 5 until 10

$('.gsw_cf.step.active > div:lt(#)').wrapAll('<div class="wrapped 5to10"/>');

anyone knows what should I add?

Thank you

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use jQuery's slice();

$('.active > div').slice(5,10).wrapAll('<div class="wrapped 5to10"/>');

$('.active > div').slice(5,10).wrapAll('<div class="wrapped 5to10"/>');
.wrapped{
background:red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container active" data-order="1">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<button>11</button>
<div>12</div>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

I found a solution that works where i use this function:

$('div[data-order="1"]').each(function(){
    $(this).children(".input_wrapper.text").wrapAll("<div class='wrapper' />");
});

I found that solution in http://jsfiddle.net/QWHYK/ and Wrapping sets of elements from a list in DIVs using jQuery

There is also, another solution in How to wrap multiple divs

about 4 years ago · Juan Pablo Isaza 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!