locked
How to add hyperlink to a image in JQuery?

    Question

  • Can any tell me how to add hyperlink to a image in jquery in this following code?

                

    $(document).ready(function ()

    {

    $("#metroaqui_novo").AddMetroSimpleButton('bt1', 'metro-verde', 'img/Imagem/policies.png', 'Policies');

    }

    Thanks in advance.

    Wednesday, January 16, 2013 7:22 AM

Answers

  • Hi Sam,

    Another option is to set the function AddMetroSimpleButton's last parameter as location.href="hyperlinkaddress", for example:

      $("#metroaqui_novo").AddMetroSimpleButton('bt5', 'metro-laranja', 'Style/Imagem/carta.png', 'Laranja', 'location.href="http://www.google.com"');

    Hope this helps, thanks.


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by SamDany Thursday, January 17, 2013 11:50 AM
    Thursday, January 17, 2013 8:18 AM
    Moderator
  • Hi Sam,

    Actually the last parameter of function AddMetroSimpleButton is pure javascript. to open in new window, you can use window.open("hyperlinkaddress","_blank"). for example:

    $("#metroaqui_novo").AddMetroSimpleButton('bt5', 'metro-laranja', 'Style/Imagem/carta.png', 'Laranja', 'window.open("http://www.google.com","_blank") ');

    Please let me know if it works on you side, thanks.


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, January 24, 2013 9:23 AM
    Moderator

All replies

  • Hi,

    Try to set as follow, and change the image's src dynamically.

    <a href="HTTP-link-here"><img src="img-link-here" width="100" height="100" border="0"></a>


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 16, 2013 9:03 AM
  • Hi Sam,

    Another option is to set the function AddMetroSimpleButton's last parameter as location.href="hyperlinkaddress", for example:

      $("#metroaqui_novo").AddMetroSimpleButton('bt5', 'metro-laranja', 'Style/Imagem/carta.png', 'Laranja', 'location.href="http://www.google.com"');

    Hope this helps, thanks.


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by SamDany Thursday, January 17, 2013 11:50 AM
    Thursday, January 17, 2013 8:18 AM
    Moderator
  • hello Yanping,

    Really thanks for your post, its working fine.

    Great Regards,

    Sam

    Thursday, January 17, 2013 11:53 AM
  • Hello Yanping,

    If i want to open the link in new window, what should i do?

    Thanks in advance.

    Regards,

    Sam

    Thursday, January 24, 2013 7:32 AM
  • Hi Sam,

    Actually the last parameter of function AddMetroSimpleButton is pure javascript. to open in new window, you can use window.open("hyperlinkaddress","_blank"). for example:

    $("#metroaqui_novo").AddMetroSimpleButton('bt5', 'metro-laranja', 'Style/Imagem/carta.png', 'Laranja', 'window.open("http://www.google.com","_blank") ');

    Please let me know if it works on you side, thanks.


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, January 24, 2013 9:23 AM
    Moderator