0

I have a JavaScript variable that I need to be a clickable image. I am able to get the image however I haven't been able to put a link on it. Please help.

var vIconYellow =  "_layouts/images/KPIDefault-1.GIF";

var vIconGreen =  "_layouts/images/KPIDefault-0.GIF";

Thank you.

0

Use jQuery to create dynamic clickable link elements.

Sample demo:

 <div id="CustomLink"></div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
    $(function () {
        var vIconYellow = "/_layouts/images/KPIDefault-1.GIF";
        var vIconGreen = "/_layouts/images/KPIDefault-0.GIF";

        var link = $('<div><p><a href="' + vIconYellow + '" id="morelink"><img src="' + vIconYellow + '" alt="vIconYellow"></a></p><p><a href="' + vIconGreen + '" id="morelink"><img src="' + vIconGreen +'" alt="vIconGreen"></a></p></div>');
        $(link).appendTo("#CustomLink");
    })       
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.