It is not possible to attach separate links to images in a JavaScript slider

I am struggling with linking individual images in a JavaScript slider for a client's website. The slider is fully functional and works well, but I can't seem to figure out how to link the images properly.

When I remove items from <--ul class="items"-->(below), I am able to add links to the <--li--> images and have them behave as normal links. However, this causes the JavaScript slider function to stop working. I have tried everything I could think of.

My objective is to link each image to its corresponding page on the site. There are a total of 4 images. I am relatively new to this kind of coding, so any assistance would be greatly appreciated.

<script>
    $(document).ready(function(){
      $('.gallery')._TMS({
      show:0,
      pauseOnHover:true,
      prevBu:'.prev',
      nextBu:'.next',
      playBu:'.play',
      duration:700,
      preset:'fade',
      pagination:$('.img-pags').uCarousel({show:4,shift:0}),
      pagNums:false,
      slideshow:7000,
      numStatus:true,
      banners:false,
      waitBannerAnimation:false,
      progressBar:false 



      })        
 })

Website

    <div class="container_12">
      <div class="grid_12">
        <div id="slide">                
            <div class="gallery">
            <ul class="items">

                    <li><a href="about.html"><img src="images/gallery-big-1.jpg" alt="">     </a></li>

                    <li><img src="images/gallery-big-5.jpg" alt=""></li>

                    <li><img src="images/gallery-big-2.jpg" alt=""></li>

                    <li><img src="images/gallery-big-6.jpg" alt=""></li>
               </ul>

            </div>
            <a href="#" class="prev"></a><a href="#" class="next"></a>
        </div>      
      </div>



#slide {  width:940px; height:415px; position:relative; overflow:hidden; z-index:2; }

.gallery {
width:940px;
position:relative;
z-index:2
}
.items {display:none;}
.pag { position:relative;}
.img-pags {position:static; left:0px; z-index:1; display:block;}
.img-pags ul {margin:0}
.img-pags li { width:200px; height:170px; margin-right:20px; display:block;     overflow:hidden;  }
.img-pags li a {position:relative;display:block;border:#f4f4f4 5px solid; }
.img-pags li a img {}
.img-pags li a span{ display:block; background:#fff;}
.img-pags li.active a,.img-pags li a:hover{border:#CCC 5px solid;}
.img-pags li.active a img,.img-pags li a:hover img{}
.prev {background:url(../images/prev-1.gif) 0 0 no-repeat; bottom:1px; left:1px;      display:block; position:absolute; width:44px;height:44px; z-index:9999;}
.next{background:url(../images/next-1.gif) 0 0 no-repeat; bottom:1px; right:1px; display:block; position:absolute; width:44px;height:44px; z-index:9999;}
.prev:hover, .next:hover {background-position: 0 bottom;}

Answer №1

Embellish your gallery images using jQuery by enclosing them in <a> tags, showcasing a demonstration on Fiddle.

HTML EMBEDDED BELOW:

<div id="slide">

  <div class="gallery">

    <ul class="items">

      <li>
        <img src="images/gallery-big-1.jpg" alt="" data-link="http://google.com" />
      </li>
      <li>
        <img src="images/gallery-big-5.jpg" alt="" data-link="http://jsfiddle.net" />
      </li>
      <li>
        <img src="images/gallery-big-2.jpg" alt="" data-link="http://stackoverflow.com" />
      </li>
      <li>
        <img src="images/gallery-big-6.jpg" alt="" data-link="http://api.jquery.com" />
      </li>

    </ul>

  </div>

  <a href="#" class="prev"></a> <a href="#" class="next"></a>

</div>

JQuery Functionality:

Suggested placement of the code prior to </body> tag.

$(function() {

  $('.gallery ul li img').each(function() {

    var imgHref = $(this).attr('data-link');

    $(this).wrap('<a href="' + imgHref + '"</a>');

  });

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The implementation of async await within a switch case statement is failing to function properly

Is it possible to wait for the resolution of a promise within a switch case statement by using the keyword await? I am facing an issue with my Angular component where the following code is causing crashes in my application. switch (this.status) { ...

Steps for displaying an error message when incorrect credentials are entered during a login attempt

As I work on implementing a login feature, I am facing the challenge of displaying an error message when users enter incorrect login credentials. My development environment involves using the POST method within Next.js. Here is a snippet of my code: ...

obtainServerSideProps query parameter

Hey there, I'm trying to use NextJS and its getServerSideProps function to send an API Request, but I'm having trouble passing my ID Query Parameter along. The URL for my API is: http://localhost:3001/product/${id} Below is my code: const rout ...

Connect-busboy: The file being piped to the write stream is either empty or incorrect, depending on its type

My current project involves testing a file upload feature using connect-busboy. Interestingly, I have encountered a peculiar issue when uploading PNG files - although the file gets uploaded, the content seems to be incorrect and unable to open. Upon furthe ...

Building Dynamic Props in Vue.js using v-select Component

I am utilizing a chart that relies on properties for data. <template> <v-row> <v-col col="12" sm="12"> <Chart :data="series2"></Chart> ### This chart receives the props < ...

Update the table in a few moments

I am struggling to refresh my table every 5 seconds but haven't been successful. <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example"> <thead> <tr> <th>Number</th> ...

Cause a bootstrap column to have overflowing content rather than expanding

I've searched extensively for the solution to my problem, but haven't found a satisfactory answer yet. My goal is to create a location finder with a map on the right and a list on the left. With over 18,000 locations to search through, the list ...

React - Material UI Divider not centered

Is the title says - my divider is not centered in the middle of my text. The current result displays a misalignment: However, I am aiming for my divider to be placed in the center like this (refer to red line): It's quite strange because according t ...

What could be the reason behind Flex making several images decrease in size?

I'm trying to set up a carousel of images with Tailwind CSS, where 5 identically sized images are displayed next to each other and can be scrolled left and right. When I imported the images without using Flex, they fit the max-width that I had specifi ...

Displaying an alert on a webpage that shows a label input using JavaScript and

I'm currently working with HTML5 and JavaScript and I'm facing a challenge. I want to create a feature where users can input any word into a label, and when they click on a button, an alert is triggered with the given text. However, despite my ...

Angular is having trouble with binding

What seems to be the issue in this code snippet? JSFiddle. function SecondCtrl($scope, Data) { $scope.data = Data; $scope.reversedMessage = function(message) { return message.split("").reverse().join(""); }; } ...

What is the best way to open the index.html file in electron?

I'm currently developing a cross-platform app using electron and Angular. As of now, the code I have for loading my index.html file looks like this: exports.window = function window() { this.createWindow = (theBrowserWindow) => { // Create ...

Tips on utilizing the enter key to add my <li> element to the list?

Currently, my to-do list setup requires users to click a button in order to add a new list item. I am looking to enhance the user experience by allowing them to simply hit "enter" on their keyboard to achieve the same result. Here is the JavaScript code I ...

Can this JSON object be created? If so, what is the process to do so?

Is it possible to create a JSON array with integers like the examples below? "data" : [ "1000": "1000", "1200": "1200", "1400": "1400", "1600": "1600", "1800": "1800", ] or "data" : [ 1000: 1000, 1 ...

Create a chronological timeline based on data from a JSON object

Here is a JSON object generated by the backend: { "step1": { "approved": true, "approvalTime": "10-11-2021", "title": "title 1", "description": "description 1" ...

Scraping a few URLs with Javascript for Web Data Extraction

I'm struggling to retrieve data from multiple URLs and write it to a CSV file. The problem I'm facing is that the fetched data is not complete (I expect 10 items) and it's not in the correct order. Instead of getting 1, 2, 3 sequentially, I ...

Activate the Select List to Appear Only When a Search is Conducted

Currently, I have implemented the react-select API in order to provide language options for selection. <Select isMulti name="langs" options={langOptions} defaultValue={{ value: "English", label: "English", nativeNam ...

Whenever I try to launch my React app using the `npm start` command in my command

After successfully creating a Simple React App and getting the happy hacking message on cmd, I encountered numerous errors when trying to run "npm start" on cmd. Despite multiple attempts at uninstalling and reinstalling node and npm, the issue persists. H ...

Obtaining a variable from within two nested functions

I'm looking for a solution where I can retrieve a variable from inside a function using an ajax call. For example: function returnStuff(){ $.ajax({ //do something }).done(function(response){ return response; }) return response; } The ...

Alter the value of a parameter within a script tag with JavaScript/jQuery

Looking to dynamically change a parameter value using JavaScript or jQuery. Here is an example URL: www.exampleurl.com/somepage?foo=test I have a function that can extract the value after the 'foo' parameter: function getParameterByName(name, ...