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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:39:55+00:00 2026-05-27T11:39:55+00:00

I have a div called ‘div.cloneFrame’, and i am cloning that using jquery.clone. it

  • 0

I have a div called ‘div.cloneFrame’, and i am cloning that using jquery.clone. it works fine and i clone all i need, using this function :

var needToClone = 4;
    var totalImgs = 0;
    for(i=0;i<needToClone;i++){
        $('div.cloneFrame').clone()
        .removeClass('cloneFrame')
        .appendTo('.frame-group').each(function(){
            var imgSrcLength = $(this).find('img');
            for(j=0;j<imgSrcLength.length;j++){
                totalImgs++;
                $(imgSrcLength[j]).attr('src','imgs/outfits/'+totalImgs+'.jpg');
            }
        })
    }
    $('div.cloneFrame').remove();

later i need to select the cloned div, for that i am using the nth child function

$('div.myframe:nth-child('+1+')').addClass('incoming').next().addClass('outgoing');

But not work. in case if i use this :

$('div.myframe:nth-child('+3+')').addClass('incoming').next().addClass('outgoing');

it’s working well. why it need skiping 2 numbers on nth-child? anything wrong from my side?

my HTML :

<div class="frame-group">

            <div class="cloneFrame myframe">
                <div id="orange-frame" class="product-frame">
                    <a class="purchase-btn" href="#">Purchase this item</a>
                    <img alt="women coat" src="imgs/yellow-coat.jpg">
                </div>
                <div id="yellow-frame" class="product-frame">
                    <a class="purchase-btn" href="#">Purchase this item</a>
                    <img alt="blue coat" src="imgs/coat-blue.jpg">
                </div>
                <div id="brown-frame" class="product-frame">
                    <a class="purchase-btn" href="#">Purchase this item</a>
                    <img alt="women shoe" src="imgs/women-shoe.jpg">
                </div>
                <div id="green-frame" class="product-frame">
                    <a class="purchase-btn" href="#">Purchase this item</a>
                    <img alt="women jean" src="imgs/jean.jpg">
                </div>
            </div>


            <span class="outfit-no">outfit no.<span>01</span></span>
            <a class="buy-outfit" href="#">Buy outfit</a>
        </div>

visit : http://jsbin.com/iquxaq/3

  • 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-27T11:39:56+00:00Added an answer on May 27, 2026 at 11:39 am

    From Jquery :nth-child() selector:

    With :nth-child(n), all children are counted, regardless of what they
    are, and the specified element is selected only if it matches the
    selector attached to the pseudo-class
    . With :eq(n) only the selector
    attached to the pseudo-class is counted, not limited to children of
    any other element, and the (n+1)th one (n is 0-based) is selected.

    Solution

    Regardless to my tests,

    • $('div.myframe:nth-child(1)') tries to look if div.myframe has a first child and if this element has class=”myframe”. In that case it is <span class="outfit-no">outfit no.<span>01</span></span> so nothing is grabbed.

    • After that for $('div.myframe:nth-child(2)') tries to grab the second child but it’s still not a .myframe, it is <a class="buy-outfit" href="#">Buy outfit</a> so nothing is stored.

    • Now $('div.myframe:nth-child(3)') tries to grab the third child and it’s a .myframe since it’s <div class="myframe"> so it stores it.

    Alternative

    In your case jquery eq() selector is more appropriate, it works great:

    // select the first child    
    $('div.myframe').eq(0);
    // instead of
    // $('div.myframe:nth-child(1)')
    

    With :eq(n) only the selector attached to the pseudo-class is counted,
    not limited to children of any other element

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

Sidebar

Related Questions

I have a div called 'divLinks' I want all links inside the divLinks to
I have created a div using jquery and put some text in it: var
I have an input box that as you type displays a div called suggestions
I have a form that validates using jquery. The form's id is contact and
I have a div called MyDiv and I have some code that hides and
I have an empty div called #lightPole that has a background image of a
I have div called panel that itself contains another div. When a user clicks
I have a div id called common, the content that I would like to
Let's say that I have a div that is called mainDiv, and it contains
I have a blank div called content. Links are later added to content using

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.