0

Is there any way to do this:

  <h1>Topology</h1>
<ul><li><a href="/"> Parent Directory</a></li>
<li><a href="File1.mp4"> File1.mp4</a></li>
<li><a href="File2.mp4"> File2.mp4</a></li>
<li><a href="File3.mp4"> File3.mp4</a></li>
<li><a href="File4.mp4"> File4.mp4</a></li>
<li><a href="File5.mp4"> File5.mp4</a></li>
<li><a href="File6.mp4"> File6.mp4</a></li>
<li><a href="File7.mp4"> File7.mp4</a></li>
<li><a href="File8.mp4"> File8.mp4</a></li>
<li><a href="File9.mp4"> File9.mp4</a></li>
<li><a href="File10.mp4"> File10.mp4</a></li>

</ul>

JSFiddle: https://jsfiddle.net/wagyox71/

Is there any way to do this without listing every single file separately?

Desii
  • 35
  • 1
  • 8

1 Answers1

1

You can do this with JavaScript.

Create a div for the list, then use a script and an array to populate the div.

The div: <div id="myLinks"></div>

    var links = ['<a href="/"> Parent Directory</a>', '<a href =""> File1.mp4</a>', 'File2.mp4', 'etc'];
    var ul = document.createElement('ul');
    document.getElementById('myLinks').appendChild(ul);

    links.forEach(function(name){
        var li = document.createElement('li');
        ul.appendChild(li);
        li.innerHTML += name;
    });

You can manually populate the links array, or do it dynamically from a directory on the site via some other call.

ztaylor54
  • 396
  • 3
  • 15
  • Is there any way to make the array contain all the files in the same directory instead of writing them one by one? I want to display about 300 files – Desii Dec 29 '17 at 03:47
  • [This](https://stackoverflow.com/questions/31274329/get-list-of-filenames-in-folder-with-javascript) answer seems to have what you're looking for. – ztaylor54 Dec 29 '17 at 03:48
  • Thank you will try – Desii Dec 29 '17 at 03:51