Skip to content
Advertisement

How to create links between dynamic content using JavaScript?

What is the best way to create links between dynamically-generated HTML content with JavaScript?

For example, I have a number of thumbnail images on a homepage that should open the matching project when clicked. I’ve come up with this solution but I’m sure there’s a better way that doesn’t involve using split() to select the correct class?

The order of the thumbnails and projects will be randomised so I can’t use the index of the thumbnail to open the project page with the same index.

https://codepen.io/wrgt1/pen/OJRwNQv

JavaScript
JavaScript
JavaScript

I’d be really grateful for any ideas!

Advertisement

Answer

Don’t see anything wrong with your code, I have also tried it in some different way

Hope you take a look at the same also

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement