Script number one performed for each of a given set of elements DOM, append to the first element of the DOM script number two.
Script number one:
function ptmedia(){
$('.ptmcss').eq(0).html('<div class="ptmcss"></div>')
.append('<div class="append"><script type="text/javascript" src="script2.js"></script></div>');
$('.spbin').each(function(){
if($(this).children().attr('class').indexOf('ptmd')!==-1){
$(this).addClass('ptmedia');ptmedia();}
Script number two does cross domain query, the fulfillment of which performs the specified function (z).
Script number two:
$.getJSON('http://example.com?callback=?',function(z){alert(z.query+'Some text');}
Due to the fact that the script is the number one multiple times, the function (z) holds an equal number of times. How to make so that the function (z) run only one time?
Thank’s for any help!
Check if the script has been appended already, if yes, don’t allow it to run.