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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:29:07+00:00 2026-05-29T19:29:07+00:00

How do I get access to live DOM collections from jQuery? Take for example

  • 0

How do I get access to live DOM collections from jQuery?

Take for example this HTML <div id='a'></div> and this JavaScript code:

var a = $('#a');
var divs = a[0].getElementsByTagName('DIV');
for(var i=0; divs.length < 20; ) {
    a.append($('<div>'+(i++)+'</div>'));
}

It will append 20 div children to <div id='a'> because divs is a live collection.

Is there anything in jQuery that I could replace the second line with to get the same result?

var divs = $('#a div'); results in infinite loop.

JSFiddle is here.

  • 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-29T19:29:10+00:00Added an answer on May 29, 2026 at 7:29 pm

    Select the element each time, this will create a new jQuery object. Which I think it the only way if the element is changing.

    var a = $('#a');
    
    for(var i=0; $('#a div').length < 20; ) {
        a.append($('<div>'+(i++)+'</div>'));
        if(i==50) break;
    }
    

    EDIT:
    Or this:

    for(var i=0, a=$('#a'); a.children('div').length < 20; ) {
        a.append($('<div>'+(i++)+'</div>'));
        if(i==50) break;
    }
    

    Or this, just one selector:

    var a = $('#a');
    var length = a.children('div').length;
    
    while(length < 20) {
            a.append($('<div>'+(length++)+'</div>'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the access token from the windows live connect api by
After realizing the difference between raw HTTP GET response and live DOM and how
I have some JQuery Code as follows: $(#sh-zone-button-cart-menu).live(click, function(event) { event.preventDefault(); $(#sh-zone-cart-menu).toggle(0, function(){ if($(this).is(:visible)){
I need to get access to the iTunes tags in an RSS feed using
Is it possible to get access to the spell checker that is incorporated in
I'm trying to get access to a form and its elements. The form is
I am looking to get access to all HTTP traffic on my machine (my
How do i get access to a control (linkbutton in my case) that is
i am trying to get access to whitepages using YQL. Unfortunately i don't have
Which permission needs my application to get access to the location of the user

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.