Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
Image will change when refresh the page and also every images will have an individual link

Image changes when the page refreshes and I am accomplishing this but I can't add individual image links. how can I do it? Please have me out.. here is the code

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <style>
        #banner-images img{
            width: 172px;
            height: 215px ;
            border: 10px solid #fff ;
        }
    </style>
</head>
<body>
     <div id="banner-images"> </div>
<script> 
var images = ['1.jpg ', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg'];
 
$('<img class="fade-in" src="images/' + images[Math.floor(Math.random() * images.length)] + '">').appendTo('#banner-images');
</script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I hope i understood your question correctly. Here is a solution.

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <style>
        #banner-images img{
            width: 172px;
            height: 215px ;
            border: 10px solid #fff ;
        }
    </style>
</head>
<body>
    <div id="banner-images"> </div>
    <script> 
        var images = [
            {src: '1.jpg', href: '#link1'},
            {src: '2.jpg', href: '#link2'},
            {src: '3.jpg', href: '#link3'},
            {src: '4.jpg', href: '#link4'}
        ];
        var random_image = images[Math.floor(Math.random() * images.length)];
        $('<a href="' + random_image.href + '"><img class="fade-in" src="images/' + random_image.src + '"></a>').appendTo('#banner-images');
    </script>
</body>
</html>

If you want to make it clearer, you can do it this way with JavaScript Template Literals.

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <style>
        #banner-images img{
            width: 172px;
            height: 215px ;
            border: 10px solid #fff ;
        }
    </style>
</head>
<body>
    <div id="banner-images"></div>
    <script> 
        var images = [
            {src: '1.jpg', href: '#link1'},
            {src: '2.jpg', href: '#link2'},
            {src: '3.jpg', href: '#link3'},
            {src: '4.jpg', href: '#link4'}
        ];

        var random_image = images[Math.floor(Math.random() * images.length)];

        $('#banner-images').html(`
            <a href="${random_image.href}">
                <img class="fade-in" src="images/${random_image.src}">
            </a>
        `);
    </script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!