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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:05:18+00:00 2026-06-15T16:05:18+00:00

I have a form and I’m dynamically adding new input & select elements in

  • 0

I have a form and I’m dynamically adding new input & select elements in to it via jQuery’s load function. Sometimes the loaded elements are in purpose empty and in that case I want to hide the container div so it won’t break the style.

The problem is, that I seem to be unable to count the loaded elements and therefore don’t know if it should be hidden or not.

For example I have this:

<div id="param_container"></div>

And on some dropdown menu change I have binded this function:

alert($('#param_container').children().length);

// Returns and loads new element correctly. Can be empty.
$('#param_container').load('/get_params', {cat:category});

if ($('#param_container').children().length ) {
    $('#param_container').css('display', 'block');
} else {
    $('#param_container').css('display', 'none');
}

alert($('#param_container').children().length);

The length of the children are always 0 even though new children element has been added.

Any thoughts?

EDIT:

My solution

$('#param_container').load('/get_params', {cat:category}, function(response) {
    if (response) {
        $('#param_container').css('display', 'block');
    } else {
        $('#param_container').css('display', 'none');
    }
});
  • 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-06-15T16:05:18+00:00Added an answer on June 15, 2026 at 4:05 pm

    The reason is that the load call is asynchronous, it completes after your function returns.

    You can use the success callback, like this:

    alert($('#param_container').children().length);
    
    // Returns and loads new element correctly. Can be empty.
    $('#param_container').load('/get_params', {cat:category}, function() {
        if ($('#param_container').children().length ) {
            $('#param_container').css('display', 'block');
        } else {
            $('#param_container').css('display', 'none');
        }
    
        alert($('#param_container').children().length);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form with input 's. When it's opened (via jQuery UI: Dialog)... cursor
I have: form.input :duration, as: select, collection: {} I need: <option value= data-price=XXX></option> Rails
I have form elements like this: <input type='text' id='person_1_name'> <input type='text' id='person_2_name'> <input type='text'
I have form where are 2 input fields and then i have dynamic dataTables
I have form with multiple input type=radio with text next to them. I want
i have form with user data to input and javascript ajax to send information
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I have form like this: <form method=POST> <p> Nazwa kategorii: <br /> <input name=NazwaKat
I have form and form text field which generates dynamically using JSP. And I'm
i have form and i am using jquery validate jquery.validate.pack.js its work fine when

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.