0

I was working on organizing a bunch of images into folders and then creating a web page so I can views them all in a nice little package. I've normalized all files and folders to be named by a basic numeric pattern. I was able to display all of the images nicely but now I want to have them all link to their respective folders.

I may not be understanding the problem well enough to be able to do an appropriate search for the answer. I'm thinking all I need to do is append my image node to an anchor node somehow.

Here is what I have so far:

<body>

<div id="volumeCovers"></div>
<script>
  var container = document.getElementById('volumeCovers');
  var images = 12;
  for (var i = 1; i <= images; i++) {
    var img = new Image();
    img.setAttribute('src', 'volumes/pics/v' + i + '.jpg');
    container.appendChild(img);
  }
</script>

<body>
3
  • 1
    What is the problem? it's not clear enough. Commented Jan 21, 2018 at 10:59
  • sorry, i writed 'link' in create tag instant of 'a'; i rewrite my code, i hope that all right. Commented Jan 21, 2018 at 18:37
  • If a link goes to a respective folder...does this folder have a page.html? Commented Jan 21, 2018 at 18:53

1 Answer 1

1

You can insert your image in links and add to container:

   for (var i = 1; i <= images; i++) {
        var img = new Image();
        let link = document.createElement('a');
        link.setAttribute('href','url');
        link.append(img);    
        img.setAttribute('src', 'volumes/pics/v' + i + '.jpg');
        container.appendChild(link);
      }

'url' replace to necessary adress. Maybe also necessary edit of css.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the prompt response but the code you provided yielded a blank screen. I reviewed for typos and still no success. You guys are great. Is there perhaps something you may have missed?
I had to modify the following line to get this to work: let link = document.createElement('link') was changed to let link = document.createElement('a')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.