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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:35:40+00:00 2026-06-14T19:35:40+00:00

I have a simple class to append a content.html file when MyClass.display() is called.

  • 0

I have a simple class to append a content.html file when MyClass.display() is called.

class MyClass
    @display: (display) ->
      $.get 'content.html', (data) ->
        $('body').append data

The code above always append the data to the end of the body.

The HTML code is simply this

<html>
  <head></head>
  <body>
    <p>text before</p>
    <script src="file.js" type="text/javascript"></script>
    <script type="text/javascript">
      MyClass.display();
    </script>
    <p>text after</p>
  </body>
</html>

I’m wondering how it is possible to append the data just after the enclosing </script> tag that triggered the function. That would in between the </script> and the following <p> tag.

One requirement is that I should not modify the HTML markup. I can not add IDs directly to markup as proposed in one of the answers below.

I know this is possible because I can see it in the Google AdSense code. But since their javascript code seems encrypted I can’t decode how its done.

Any idea how to achieve this?

  • 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-14T19:35:42+00:00Added an answer on June 14, 2026 at 7:35 pm

    While javascript code is running, its containing script tag is the last element available in the DOM object

    You can grab its reference for example like this,

    var ele = $('script:last');
    

    From there, depending on the content of content.html you can do the necessary work to place content after the script tag (not append inside the script tag, that’ll not be what you’re looking for)

    e.g. If content.html has its own top level element, p

    <p>
      <strong>hello</strong> world!
    </p>
    

    then you can simply

    var MyClass = {
      display: function() {
        var ele = $('script:last');
        $.get('content.html', function(data) {
          ele.after(data);
        });
      }
    }
    

    note 1: you must get reference ele outside of the $.get callback. the callback runs asynchronously – by then the DOM would’ve likely loaded more elements and script:last may not be your script tag anymore.

    note 2: if content.html does not contain a top level element that wraps the entire thing, then you’d have to wrap it yourself in the callback, e.g. ele.after("<div class='my-own-wrapper'>" + data + "</div>");

    For reference: https://gist.github.com/4122339

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

Sidebar

Related Questions

hy everyone, i have simple html code showing a table width html <table class=table_site>
I have a simple Class Hierarchy that I am trying to get to work
I have an simple class that I get from a webservice. public class person
I have simple class with width and height member fields which define number of
I have a simple class Student under namespace School. namespace XmlTestApp { public class
I have a simple class for use on JNI, which i need to export
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I have a simple class I'm serializing. [DataContract(Name = Test, Namespace = )] public
I have a simple class that contains some general information about the current web
I have a simple class library (COM+ service) written in C# to consume 5

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.