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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:09:19+00:00 2026-05-15T06:09:19+00:00

I have thrown together a quick prototype to try and establish a few very

  • 0

I have thrown together a quick prototype to try and establish a few very basic truths regarding what inline JavaScript can do when it is loaded with AJAX:

index.html

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    </head>
    <body>
            <script type="text/javascript">
                    $('p').css('color','white');
                    alert($('p').css('color'));
                    // DISPLAYS FIRST but is "undefined"

                    $(document).ready(function(){
                        $('#ajax-loaded-content-wrapper').load('loaded-by-ajax.html', function(){
                            $('p').css('color','grey');
                            alert($('p').css('color'));
                            // DISPLAYS LAST (as expected)
                        });
                        $('p').css('color','purple');
                        alert($('p').css('color'));
                        // DISPLAYS SECOND
                    });
            </script>
            <p>Content not loaded by ajax</p>
            <div id="ajax-loaded-content-wrapper">
            </div>
    </body>
</html>

loaded-by-ajax.html

<p>Some content loaded by ajax</p>

<script type="text/javascript">

    $('p').css('color','yellow');
    alert($('p').css('color'));
    // DISPLAYS THIRD

    $(document).ready(function(){
        $('p').css('color','pink');
        alert($('p').css('color'));
        // DISPLAYS FOURTH
    });

</script>

<p>Some content loaded by ajax</p>

<script type="text/javascript">

    $(document).ready(function(){
        $('p').css('color','blue');
        alert($('p').css('color'));
        // DISPLAYS FIFTH
    });

    $('p').css('color','green');
    alert($('p').css('color'));
    // DISPLAYS SIX

</script>

<p>Some content loaded by ajax</p>

Notes:

a) All of the above (except the first) successfully change the colour of all the paragraphs (in firefox 3.6.3).
b) I’ve used alert instead of console.log as console is undefined when called in the ‘loaded’ HTML.

Truths(?):

  1. $(document).ready() does not treat the ‘loaded’ HTML as a new document, or reread the entire DOM tree including the loaded HTML, it is pointless inside AJAX loaded content
  2. JavaScript that is contained inside ‘loaded’ HTML can effect the style of existing DOM nodes
  3. One can successfully use the jQuery library inside ‘loaded’ HTML to effect the style of existing DOM nodes
  4. One can not use the firebug inside ‘loaded’ HTML can effect the existing DOM (proven by Note a)

Am I correct in deriving these ‘truths’ from my tests (test validity)?
If not, how would you test for these?

  • 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-15T06:09:19+00:00Added an answer on May 15, 2026 at 6:09 am

    We can narrow it down to one even simpler truth: all the .load() function does is add content to your page.

    Regarding #1, the document is already loaded, so no, you are not loading a whole new document. You are merely adding content in the middle of the document that’s already there. However, the nodes really are added to the DOM where you’ve asked that they be added. This doesn’t require “rereading the entire DOM tree,” but the effect is the same.

    You’re correct on #2: any JavaScript you inject onto your page can absolutely affect anything on your page in any way, including its styles. The newly loaded scripts have no way to know which elements were there before and which are new; it just sees the DOM as it currently exists.

    You’re likewise correct on #3. jQuery is on the page, and the new script has no idea that it was loaded separately. It’s just code being executed on your page.

    You’re incorrect on #4. Firebug is a fantastic tool for analyzing what’s currently on the page, regardless of how it got there. You’ll always see the current DOM in Firebug, and it will even highlight (in yellow) any changes as they’re made in real time.

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

Sidebar

Related Questions

I have a quick question regarding debug and release in VS 2008. I have
Does anyone have any tips for dealing with ConstraintExceptions thrown by XSD datasets? This
Ok, I have a strange exception thrown from my code that's been bothering me
I'm making my way into web development and have seen the word postback thrown
I need to throw together a quick CRUD asp.net site, but this may become
I have an application that seems to throw exceptions only after the program has
I have the following code in WCF service to throw a custom fault based
We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests
I have this factory method in java: public static Properties getConfigFactory() throws ClassNotFoundException, IOException
I have a large 2d array that I serialize and base64_encode and throw into

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.