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

  • Home
  • SEARCH
  • 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 8387935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:21:08+00:00 2026-06-09T18:21:08+00:00

Let’s do code first: $(function(){ //Step-2) Load and a template from server and APPEND

  • 0

Let’s do code first:

$(function(){

   //Step-2) Load and a template from server and APPEND to BODY  
   function loadTemplate(path, callback) {
        $.get(path, null, function (t) {
            $('body').append(t);
        }, 'text');

        if (callback != undefined && typeof (callback) == 'function') {
            callback.apply(window);
        }
    }

    //Step-3) a callback method
    function showProduct() {
        //setTimeout(function () {
        //    $('#prodBasicView').tmpl(prod).appendTo('#prodView');
        //}, 100);

        alert($('#prodBasicView').length); // it alerts 0, But I am expecting 1

    }

    //Step-1) initiating loading template
    loadTemplate('/template/remote-template2.htm', showProduct);
});

remote-template2.htm :-

     <div id="prodBasicView" style="display:none;">
       <div class="myProd">
        <h3> Product Name</h3>
           <span>Price: $ 700 </span>
       </div>
     </div>

ISSUE:

  • loadTemplate method successfully loaded a template (remote-template2.htm) and append to body.
  • After successfully loaded the template the passing callback function showProduct method get fired.
  • Inside showProduct method I am trying to use loaded template ($(‘#prodBasicView’)) but it returns empty array.
  • But if I delay the execution of showProduct with few millisecond it works but I don’t think its a good practice
  • The above point seems to be appended DOM elements are not ready

  • HOW TO MAKE SURE MODIFIED/ MANIPULATED DOM IS READY AGAIN BEFORE USING THEM ??

  • 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-09T18:21:10+00:00Added an answer on June 9, 2026 at 6:21 pm

    It seems to me that you just need to put the callback-calling code within the $.get callback, like so:

    function loadTemplate(path, callback) {
        $.get(path, null, function (t) {
            $('body').append(t);
            if (callback != undefined && typeof (callback) == 'function') {
                callback.apply(window);
            }
        }, 'text');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's first take a look at JavaScript code => function ConstructNodes(className,hiddenId,alertMsg,formName){ this.className = className;
Let's take a common example how a haskell function can be called from a
Let's say I have an facebook application running using the JS SDK. First user
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say, if I need to assign an id to element with first name,
Let's say I have multiple requirements for a password. The first is that the
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's suppose I have this piece of code. foreach(string value in myList) { string
Let's say I have a javascript array with a bunch of elements (anywhere from

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.