-3

On a image inside link instead of use link href i would like to use img src to redirect to image path.

with this is possible to get the img src but how to use src to redirect? thank's

 $(".drop a").click( function() {
     alert($(this).children('img').attr('src'));
 });

<div class="drop">
<a href""><img src=".." /></a>
</div>
japalow
  • 23
  • 7
  • Does alert gives you proper URL? – Rajesh Mar 05 '17 at 04:47
  • 1
    Possible duplicate of [How do I redirect to another page in JavaScript/jQuery?](http://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-page-in-javascript-jquery) – Rajesh Mar 05 '17 at 04:48
  • @Rajesh yes! give – japalow Mar 05 '17 at 04:58
  • Then please refer duplicate link to see different approaches to redirect and if it satisfies your requirement, accept this as duplicate so that no one answers it – Rajesh Mar 05 '17 at 05:02
  • that is a redirect this is redirect based on img src. don't get consused @Rajesh – japalow Mar 05 '17 at 05:04
  • You are able to get url in a variable, so the real problem was *How to redirect using this value*. So yes its a duplicate. Fetching url from img is a specific usecase but underlying problem and solution are same – Rajesh Mar 05 '17 at 05:06

1 Answers1

-1

Just use window.location

Code:-

$(".drop a").click( function() {

     window.location = $(this).children('img').attr('src');
     return false;
});
Arshid KV
  • 9,631
  • 3
  • 35
  • 36
  • Though your answer is correct, you should choose to close it as duplicate as this is a very obvious duplicate – Rajesh Mar 05 '17 at 04:48