Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't want to suggest to do it this way, but because you want to to know how this can be done, here some code to illustrate how it could be done (only rudimentary tested and should not be used without further testing).</p> <p>While I'm not sure if you could (and i think you should not) structure your project that way i hope that it will help to solve your problem.</p> <p>The main code of your page:</p> <pre><code>var app = {}; (function() { var nextId = 1; var elementById = {}; app.registerContent = function( id, initFunction ) { try { initFunction(elementById[id]); } catch( e ) { //if an error happend in the init script catch it so that the script will not break console.error(e); } //remove the jquery element from the list delete elementById[id]; } //custom loader to handle init script jQuery.fn.customLoader = function(url) { var elm = $(this); var id = nextId++; //store the element where the data is loaded to in a list elementById[id] = elm; $.get(url,function(data) { //replace the id in the script so that the element the data is loaded into // can be passed to the init script later. data = data.replace("%%unique-id%%",id); elm.html(data); //append the data to the element }); } //a sample how you would load the content $(function() { $(".dest").customLoader("content.html"); }); })(); </code></pre> <p>The code in your requested data:</p> <pre><code>&lt;div&gt;some content&lt;/div&gt; &lt;!-- the script that correspons to that part --&gt; &lt;script&gt; //create a scope using a function that is executed directly (function() { //using var to make the variables only visible to this place var uniqueId = %%unique-id%%; //this will be replaced by the loader to identify the element where the data is loaded to var someVar = 1; app.registerContent(uniqueId, initFunctionForTheContent) function initFunctionForTheContent(element) { element.css("background-color", "red") } })(); &lt;/script&gt; </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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