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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:25:01+00:00 2026-05-16T22:25:01+00:00

I have some javascript which will create some sort of widget on a page.

  • 0

I have some javascript which will create some sort of widget on a page. I will be giving this snippet to clients so I want them to have to do very little.

The most obvious solution which I have work right now looks something like this:

<div id="divContent"></div>
<script type="text/javascript">
    MakeWidget('divContent');
</script>

Make widget basically looks for the divContent div and fill it with my widget’s html.

Is there a better way to do this?
Can you replace a Script Tag with a Div using Javascript in that Script Tag?

I would really like it if I could reduce the code down to only the MakeWidget function and it would replace itself and the script tag with the html the function generates.

Edit – I essentially want to generate HTML exactly where the MakeWidget function is called on the page.

  • 1 1 Answer
  • 2 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-16T22:25:02+00:00Added an answer on May 16, 2026 at 10:25 pm

    Can you replace a Script Tag with a Div using Javascript in that Script Tag?

    Yes. When the <script> element is reached, assuming it is not a defer or async script, it will be the last script element in the page so far. So you can say, either inline or in an external script:

    <script type="text/javascript">
        (function() {
            var scripts= document.getElementsByTagName('script');
            var script= scripts[scripts.length-1];
            var div= document.createElement('div');
            div.innerHTML= 'Whatever content is going to be inserted';
            script.parentNode.insertBefore(div, script);
        })();
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some javascript which I want to convert to jQuery... I thought it
I have some javascript which catches changes to a form then calls the form's
I have some Javascript attached to the Service Activity form which fires OnLoad. It
Hi I have a usercontrol which includes some JavaScript, if I add the control
I am using some pre-written JavaScript from polldaddy. They have a JavaScript option which,
I have a javascript function which needs to do a numerical calculation. Some of
We are starting to create an application using JavaScript and HTML5 which will use
I have an asp.net web page written in C#. Using some javascript I popup
The situation is this: I have some JavaScript that creates an interactive dialogue (and
I have some javascript where I append an option to a select: var myuniqueddl

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.