0

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

2 Answers 2

1

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>

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.