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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:16:38+00:00 2026-06-15T08:16:38+00:00

Say I want to print html from inside a script tag. A source like

  • 0

Say I want to print html from inside a script tag.

A source like this

<div>foo</div>
<script>
print('<div>Print this after the script tag</div>');
</script>
<div>bar</div>

should look something like this in browser after the script has run

<div>foo</div>
<script>
print('<div>Print this after the script tag</div>');
</script>
<div>Print this after the script tag</div>
<div>bar</div>

I could write my own code for this purpose but since this looks to me like a very simple problem, I’m guessing either I’ve missed something or my thinking is flawed in some way and printing is left out intentionally.

Also, somewhat related: I’d like to know if a script is (or can be made) aware of the script tags surrounding it. With this information it would be much easier to find the position for the printed html code to be injected into, assuming it’s not highly discouraged.

To clarify: I don’t need you to write a print function for me. I only need to know if a native method to achieve this exists and I’ve missed it or alternatively the reason it shouldn’t be done.

EDIT
I realized that I didn’t think the question through.

I got my facts straight and now almost everything seems to be working. I should’ve originally mentioned that the print function was needed inside templates – I’m working on a template engine experiment. I managed to work it out by separating scripts from plain html and concatenating the split html sans scripts with script output.

As I was writing the code I noticed that everything wouldn’t go so smooth because of the asynchronous nature of js. I guess I was expecting to be able to do any kind of js magic in templates, just like I could in php. Seems like actually supporting async code in a fool-proof manner inside templates will require some more thought.

  • 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-15T08:16:39+00:00Added an answer on June 15, 2026 at 8:16 am

    You need to use document.write()

    <div>foo</div>
    <script>
    document.write('<div>Print this after the script tag</div>');
    </script>
    <div>bar</div>
    

    Note that this will only work if you are in the process of writing the document. Once the document has been rendered, calling document.write() will clear the document and start writing a new one. Please refer to other answers provided to this question if this is your use case.

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

Sidebar

Related Questions

Say if i want to print out my integer stored inside a array ,
Let's say I want to do something like this void my_printf(char *fmt,...) { char
Say I want to write a function like this: int get_some_int(string index) { ...perform
Say I have the code: print(>>> ) command = gets What I want to
I have 2 pages, say page1.html and page2.html. page1.html has this code: $(document).ready(function() {
I want to pause the timer thread....or i can say want to put it
Say I want to draw a Ball in the scene and here are two
Say you want to install a library lib-a which has dependencies dep-1 and dep-2
Say I want to disassemble lines m-n of file x, where file x is
Say I want to have a method that takes any kind of number, is

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.