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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:03:00+00:00 2026-05-17T19:03:00+00:00

For example <script> function foo(){…} </script> <div><script>foo();</script></div> <span><script>foo();</script></span> and I wanted to have foo

  • 0

For example

<script>
function foo(){...}
</script>

<div><script>foo();</script></div>
<span><script>foo();</script></span>

and I wanted to have foo return “abc” when called from a div, return “123” when called from a span.

Is this possible?

  • 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-17T19:03:00+00:00Added an answer on May 17, 2026 at 7:03 pm

    After reading your comment I think you should do something else:

    1. create empty elements where your ads should appear (#ad1_empty, #ad2_empty, …)
    2. place your ad code at the bottom of the page hidden (#ad1_full, #ad2_full, …)
    3. when the document is ready, replace all empty elements with the real ones

    // code

    <div id="ad_empty"><!-- placeholder --></div>
    <div id="ad_content" style="display: none;">
        <script src="[ad resource]"></script>
        <script>inline ad script</script>
    </div>
    
    <script>
    function replace( oldel, newel, show ) {
      if ( typeof newel == "string" ) 
        newel = document.getElementById( newel );
      if ( typeof oldel == "string" ) 
        oldel = document.getElementById( oldel );
      if ( newel && oldel )
        oldel.parentNode.replaceChild( newel, oldel );
      if ( show ) 
        newel.style.display = "";
    }
    
    window.onload = function() {
        replace( "ad_empty",  "ad_content",  true );
        replace( "ad_empty2", "ad_content2", true );
    };
    </script>
    

    It is possible to do what you originally wanted, btw (but it’s useless)

    function foo() {
    
      var scripts = document.getElementsByTagName("script");
      var parent = scripts[scripts.length-1].parentNode;
      var tag = parent.nodeName.toUpperCase();
    
      if (tag == "DIV") {
        alert("called from a <div>");
      } else if (tag == "SPAN") {
        alert("called from a <span>");
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Perl script with many defined constants of configuration files. For example:
For example: script.js: function functionFromScriptJS() { alert('inside functionFromScriptJS'); } iframe.html: <html> <head> <script language=Javascript
Does anyone have an example of script that can work reliably well across IE/Firefox
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
This works (prints, for example, 3 arguments): to run argv do shell script echo
I have to request data for a JS-script from a MySQL database (based upon
For example if I add four (blank) script tasks A1, A2, B1, and B2,
As a simple example, I want to write a CLI script which can print
For example: using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Serialization;

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.