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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:56:08+00:00 2026-06-14T03:56:08+00:00

Before calling my question a duplicate of this one , please read my question

  • 0

Before calling my question a duplicate of this one, please read my question through.

I have a set of demo pages for my blog posts. These pages can have CSS, HTML, jQuery/JS, or any combination of the three. The page is organized as follows:

<div id="page-wrapper">
<style type="text/css">
//CSS here.
</style>

<!--Include jQuery here-->
<script type="text/javascript">
//JS here
</script>

<!--Demo HTML would go here-->
</div>

(I know style tags in the body are bad, I have my reasons.)

After the page-wrapper div, I include a JavaScript source file that creates a “View Source” link/button.

The problem arises because the demo JavaScript may contain changes to CSS, and these changes show up in the demo HTML (e.g. style="color: #ff0000; ") since the code is being “gotten” by the JavaScript source file at the end, as follows:

var sourceCode = "<!DOCTYPE HTML>\n<html>" + $('html').html() + "\n</html>";

I want the demo jQuery to execute last; that is, after the source file inclusion is executed. I can’t do the following things:

  1. Move the source-file inclusion/reference to the <head> tags because jQuery is included in the body. This is so that source code viewers know I’m using jQuery.
  2. Add code to the demo JavaScript for it to wait, since source code viewers would be confused.
  3. Make the demo JavaScript wait too long since viewers are impatient 🙂

Is there a solution?

  • 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-14T03:56:10+00:00Added an answer on June 14, 2026 at 3:56 am

    It looks like you’re creating something like jsFiddle or jsBin.

    What you can do is make sure that the JS code that you want to inject into your template gets injected into a function callback. The onload event sounds like it should do what you want.

    <div id="page-wrapper">
        <style>
            <!-- ### demo CSS -->
        </style>
        <script>
            (function ($) {
                $(window).load(function () {
                    <!-- ### demo JS -->
                });
            })(jQuery);
        </script>
        <!-- ### demo HTML -->
    </div>
    

    Depending on your implementation, that may not work, so you can try triggering a custom event callback instead, if onload doesn’t cut it.

    <script>
        (function ($) {
            $(window).on('my.custom.event', function () {
                <!-- ### demo JS -->
            });
        })(jQuery);
    </script>
    <!-- ### demo HTML -->
    <script>
        jQuery(window).trigger('my.custom.event');
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Java 6 API question. Does calling LockSupport.unpark(thread) have a happens-before relationship to the return
Before you outright close out this question as a duplicate, it's worth noting that
I know that I should have schema of a table before calling NewRow method
before I start I want to point out that I tagged this question as
I have a question regarding the ||= statement in ruby and this is of
I have a simple question hopefully - how does one free memory which was
Please note that this is asking a question about constructors, not about classes which
I have this question when I am studying an open source Android project. I
This question is quite simple but I have run into the problem a few
I have seen this question in SO several times. Most of cases user called

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.