Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is how I would do it:
- I would use classes instead of IDs, this way I don't have to care about unicity:
- <script src="./bundle/src/js/api.js" class="test-api" data-client="2"></script>
- <script src="./bundle/src/js/api.js" class="test-api" data-client="5"></script>
- <script src="./bundle/src/js/api.js" class="test-api" data-client="6"></script>
- Then, the first thing I would do inside the script is try to find `.test-api` scripts which have not been processed yet. And mark them with another class when I find them:
- var elementsToProcess = document.querySelectorAll('.test-api:not(.processed)');
- for (var i = 0; i < elementsToProcess.length; i++) {
- var el = elementsToProcess[i];
- el.classList.add('processed');
- var clientId = el.getAttribute('data-client');
- initClient(clientId);
- }
- function initClient(clientId) { /* Your logic for a given client... */ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement