I have a script named as view.js which does is counts the number of times a single div box is viewed on the page..... I have that mechanism well working when I load that script into only one div ...... but when I put that inside multiple divs inside single page it only works for the last script...... I know that js are loaded sequentially on a page ie only my last loaded scipt is suppose to work
can anyone tell me a way so that when I load my js multiple times inside different div they act as different scripts and run in parallel for count
and I also want to mention that the variable names will remain same for every script and I just want to use them differently for other scripts
also is there any solution using the js object... please let me know of the solution
<div id="parentofad" >
<div id="ad">
<img src="gemma-correll-cool-beans-button-magnet-lg.jpg" width="100" height="100">
</div>
<script type="text/javascript" src="adTagScript.js"></script>
</div>
<div id="parentofsecondad" >
<div id="ad">
<img src="gemma-correll-cool-beans-button-magnet-lg.jpg" width="100" height="100">
</div>
<script type="text/javascript" src="adTagScript.js"></script>
</div>
Edited: jsfiddle snippet https://jsfiddle.net/1fxgwztk/