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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:36:42+00:00 2026-05-16T18:36:42+00:00

I have a <script> where it adds to the <head> another script. This new

  • 0

I have a <script> where it adds to the <head> another script.
This new script is supposed to find the original <script> that inserted it.
can I put <script id="blablabla"> and let the new <script> find it?

<div id="placeholder-1"></div>
<script type="text/javascript">
            <//![CDATA[
            (function() {
             var s = document.createElement("script");
             s.type = "text/javascript";
             s.async = true;
             s.src = "blablabla.com/blabla.js";
             (document.getElementsByTagName("head")[0] ||
              document.getElementsByTagName("body")[0]).appendChild(s);
             })();//]]></script>

Now, the blabla.js needs to find the div placeholder.
I am trying to save that div placeholder, by giving it’s id already to the script.

is that a browser compatible?

thanks

  • 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-16T18:36:42+00:00Added an answer on May 16, 2026 at 6:36 pm

    In HTML 5, just place an id attribute on the script tag.

         <script id="myscript">
             // Your script here
         </script>
    

    In HTML 4, the id tag isn’t actually defined as being valid on a script tag.

    http://www.w3.org/TR/html4/interact/scripts.html#edef-SCRIPT Official W3C Specification

    Only src, type, langugage, defer and charset are officially allowed.

    A valid work around would be this…

    <div id="scriptcontainer">
         <script type="text/javascript">
             // Your script here
         </script>
    </div>
    

    You can now traverse to the script using the id of the div element in your “blabla.js”

    var myScript = document.getElementById("scriptcontainer").getElementsByTagName("script")[0];
    

    So essentially, by nesting the script inside of an element with an id, we can get to the script from another script and also have valid markup.

    Additional note: in the HTML 4 spec, id was genuinely not allowed on the script tag:

    id All elements but BASE, HEAD, HTML, META, SCRIPT, STYLE, TITLE ID
    #IMPLIED document-wide unique id

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

Sidebar

Related Questions

I have this script in BASH (linux) shells script that adds all *.jar files
I have an script that adds products to a remote database using a RESTful
I have a JS/jQuery script that adds our leads (web contacts) to the DOM
I have found a script that adds mouse trail on Opera's mouse gesture. Very
I have a script that loops and adds markers one at a time. I
I have a script that adds all children from the current clicked element to
I have a script that adds images to my products. It is used to
I have a problem with using a script that adds a NiceEdit toolbar to
I have this structure for one of my pages: head script /script /head body
I have a GM script that adds buttons next to certain hyperlinks on Facebook

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.