Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to parse text as JavaScript?
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/3057628/how-to-self-identify-the-position-of-a-scripts-tag-in-the-dom">This question of mine</a> (currently unanswered), drove me toward finding a better solution to what I'm attempting.</p> <h2>My requirements:</h2> <p>&bull; Chunks of code which can be arbitrarily added into a document, without an <code>id</code>:</p> <pre><code>&lt;div class="thing"&gt; &lt;elements... /&gt; &lt;/div&gt; </code></pre> <p>&bull; The objects are scanned for and found by an external script:</p> <pre><code>var things = yd.getElementsBy(function(el){ return yd.hasClass('thing'); },null,document ); </code></pre> <p>&bull; The objects must be individually configurable, what I have currently is identifier-based:</p> <pre><code>&lt;div class="thing" id="thing0"&gt; &lt;elements... /&gt; &lt;script type="text/javascript"&gt; new Thing().init({ id:'thing0'; }); &lt;/script&gt; &lt;/div&gt; </code></pre> <p>&bull; So I need to ditch the identifier (<code>id="thing0"</code>) so there are no duplicates when more than one chunk of the same code is added to a page</p> <p>&bull; I still need to be able to config these objects individually, without an identifier</p> <hr> <p>SO! All of that said, I wondered about creating a dynamic global variable within the script block of each added chunk of code, within its script tag. As each 'thing' is found, I figure it would be legit to grab the innerHTML of the script tag and somehow convert that text into a useable JS object.</p> <p>Discuss.</p> <p>Ok, don't discuss if you like, but if you get the drift then feel free to correct my wayward thinking or provide a better solution - please!</p> <p>d </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload