javascript - Can't load multiple document.write scripts -


i'm trying load multiple document.write scripts single document. this:

:docwrite.js

document.write('<a href="#"><img src='myimage.gif'/></a>'); 

myhtml.html

$('.myclass').each( function( index, element ){     var script = unescape('%3cscript src="'+docwrite.js+'" type="text/javascript"%3e%3c/script%3e');     $(element).html( script );  }); <div class="myclass">document.write loads image here</div> <div class="myclass">stops here , hangs</div> <div class="myclass">same</div> 

the first div loads script , image written inside stops after that. change docwrite.js don't have access it. ideas how can fix this? in advance.

i think you're missing quotes around docwrite.js, try instead:

$('.myclass').each( function( index, element ){     var script = unescape('%3cscript src="' + 'docwrite.js' + '"type="text/javascript"%3e%3c/script%3e');     $(element).html( script ); }); 

i added single quotes around "docwrite.js". without quotes, javascript interpreter think docwrite object , you're trying access js property on object.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -