• Hi,

    I’m hoping someone with some basic JQuery/Javascript knowledge can help me with adding a hyperlink to an image in a slider.

    If i had an image with the class “home-img” how could i forward this to a specific url i.e “www.example.com”?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • @jackie-chan

    You have not provided enough information to provide support for your specific request.
    However, in general :

    <div class="slider-here">
     <a href="https://www.example.com"><img class="home-img" src="/path-to-image" /></a>
    </div>
    Thread Starter Jackie Chan

    (@jackie-chan)

    @corrinarusso thanks for your reply, i want to target the class using javascript/jquery/php to add the hyperlink as i can’t go in and adjust the html/css as it’s a slide set up in a module.

    So i’m basically looking for a general way to add hyperlinks to a specific class via some sort of function,

    Hope that makes more sense

    @jackie-chan

    There’s still not really enough information as to what and why you are trying to do this. More context would be helpful. However, generically, you want the browser to read in the page and if it finds a particular class, then wrap the text within that class to a hyperlink. Sounds wonky, but is js it will be something like this :

    $( document ).ready(function() {
        $('.your-new-class').contents().wrap('<a href="https://www.corrinarusso.com"></a>');
      });
    .........
    <span class="your-new-class">Check out my site</span>

    I’ve not tried this method, however it looks as tho it may be a little cleaner using jQuery – here’s a good example :
    https://www.tutorialrepublic.com/faq/how-to-change-href-attribute-of-a-hyperlink-using-jquery.php

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a hyperlink to a div class’ is closed to new replies.