Iteration through folders

I have a list of elements, all of which are wrapped div, and each element is inside the <p> . I need to add

 <a href="../Filepath/Followed by, in numerical order, 7.html ---> all the way through infinity. 

So for example, if I have 100 elements, all with

 <p> 

then I want the corresponding number

 <a href> 

tags to be generated.

I thought a loop would be a good solution, but I can't come up with a circuit to make it work.

I started with code, and this is what I came up with. Keep in mind that I store all html files in a folder that I access through a script. All of them are numbered from 7 ++ ...

HTML

 <div class="container"> <p>Textual description of item</p> ... </div> 

Javascript

 $(document).ready(function() { var files = {'.html':100}; var pageName = ""; var html = "", src; for (var ext in files){ for (var i = 0; i < files[ext]; i++){ src = "../Filepath/[i]/" + pageName + "-" + (i+1) + "." + ext; html += '<a href="'+src+'"></a>'; } $("container").prepend(html); }}); 

(the script is not finished, so feel free to change it completely if you have a better approach

+4
source share
1 answer

This line

 src = "../Filepath/[i]/" + pageName + "-" + (i+1) + "." + ext; 

supposed to

 src = "../Filepath/[" +i + "]/" + pageName + "-" + (i+1) + "." + ext; 
+3
source

Source: https://habr.com/ru/post/1442349/


All Articles