Inserting Javascript via jQuery?

Hi there,

I have a ul with 8 li’s in that are generated dynamically. What I would like to do is insert a block of code to replace the 4th li.

I have this simple code:
jQuery("ul.products li:nth-last-of-type(4)").html("test");

which works fine with HTML, but is there a way I can insert a block of code that includes a reference to an external JS file?

Something like:

<script src="https://www.external.com/file.js">
<script>some other js code here</script>

Is this possible?

Thanks

Hi @toolman, yes you can create a script element, set it’s src property and finally append it to the body:

Though qualifiers do apply; namely that your additional script wont be available before it is loaded, so it can’t inject data into on-load events, etc.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.