Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have couple of issues here.</p> <pre><code>for (var idx=0; idx&lt;scriptx.length; idx++) { if (jQuery(scriptx[idx]).is("#inline-comments")) { scripts[idx] = scriptx[idx].text; } } </code></pre> <p>You are incrementing the loop iteration variable eventhough there is no match and you dont want to push any item to the array. So if the first script does not match your condition <code>scripts[0]</code> will be undefined hence you get the error when you tru to acces the property <code>length</code> of undefined in your condition <code>if (scripts[idx].length!=0) {</code></p> <p>Another issue is that <code>scriptx[idx].text</code> here text is a function so you want the real text of the element and not the function reference so you should write <code>jQuery(scriptx[idx]).text()</code> or <code>scriptx[idx].innerHTML</code>. Since you are using id and ids are not supposed to be duplicated you can simply write this as:</p> <pre><code> var txt = jQuery('#inline-comments').text(); if (txt.length) { try { // create a function for the script &amp; execute it f = new Function(scripts[idx]); f(); } catch(se) { } // end try-catch } // end if </code></pre> <p>If you plan to turn <code>inline-comments</code> to class from id and you are looking to access multiple of them then this should work.</p> <pre><code> scripts = []; for (var idx=0; idx&lt;scriptx.length; idx++) { if (jQuery(scriptx[idx]).is(".inline-comments")) { scripts.push(scriptx[idx].innerHTML); } } // execute each script in turn for(idx=0; idx&lt;scripts.length; ++idx) { var content = scripts[idx]; if (content.length) { try { // create a function for the script &amp; execute it f = new Function(content); f(); } catch(se) { } // end try-catch } // end if } // end for </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.
    3. 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