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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:21:20+00:00 2026-06-18T07:21:20+00:00

I have a question about inserting html with JavaScript into the DOM after an

  • 0

I have a question about inserting html with JavaScript into the DOM after an Ajax call using JQuery’s .load().

Assume the following sample html section:

<script>$(document).ready(function(){var e = $('#'+'@Servergenerated');})</script>

<div id='@Servergenerated'>Test Element</div>

If I return the above section through an Ajax call and insert the result into the DOM using JQuery’s load() function — Will both the markup rendering and the script execute as a blocking call?
Meaning, since .load() executes on the single thread available to JavaScript, will it ensure that both the markup rendering and the JavaScript execution will finish before other JavaScript on the same main page can be invoked ?

The Ajax request is initiated through $("#someElement").load(..)

In the above case, can I always assume that the JS is always paired up with the correct html (so that the JS will execute against the ID that is currently defined on the page)

However, is there a difference between using .load() and .html().

Typically I use $.get to retrieve the data and then insert it into the DOM using .html(). This code is however in a third party library and it’s uisng .load() instead..

  • 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-18T07:21:22+00:00Added an answer on June 18, 2026 at 7:21 am

    When you use $().load(url,fn), code that follows that line will execute before the html is appended to the page because $().load(url,fn) performs an asynchronous http request to get the content. See examples at end.

    Another important thing to remember is that with $().load(url,fn), if the html returned contains javascript, that javascript may execute before the content exists on the page resulting in plugins not being initialized properly. This is why it is strongly suggested that you should not use $().load(url,fn) to bring in content that contains scripts.

    Examples:

    console.log(1)
    $("#div1").load("page1.html",function(){
        console.log("4 maybe 5")
    });
    console.log(2)
    $("#div2").load("page2.html",function(){
        console.log("5 maybe 4")
    });
    console.log(3)
    

    In the above example, logs 1 2 and 3 are garunteed to happen in that order, however 4 and 5 may swap positions depending on which ajax request completes the fastest. There is no way of avoiding that other than not using $().load(url,fn) or requesting div2’s content in the success of requesting div1’s content.

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

Sidebar

Related Questions

I have a question about inserting values into an input field from my MYSQL
I have a question about inserting a dynamically created script with JavaScript. This is
I have a question about inserting column stored procedure into table. I have two
I have question about parsing in Html helper : I have sth like: @foreach
I have question about XSLT1.0. The task is to write out in HTML all
Earlier, a question was asked about inserting a terminal directly into Ruby Mine on
Hi I have a question about preloading images either in JS or jQuery. What
Previously I've asked about inserting a column into a dataset . I now have
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about normalization. Suppose I have an applications dealing with songs. First

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.