Imagine you have a script that loads right away when a page loads.
Now, what happens if the script src changes when you click on a button? Will the new src get executed?
Here is some example code:
<button>
click
</button>
<script class="tracking" src="www.gamespot.com"></script>
And here's the JavaScript part:
$("button").on("click",function(){
$.ajax({
url: url,
dataType: "script",
success: console.log("success")
});
});
var url = "www.test.com";
I thought about adding the second script to the DOM when the button is clicked, but it didn't work as expected in jsfiddle. I'm not sure if that method actually works...