Search code examples
jqueryattributeshyperlinkelementsrc

jQuery taking a <img src> in <a> tag to variable


I want to write to var adres a src value of an img in rollovereed element

structure is:

<div>
 <a class="link" href="#">
    <img src="value" />
 </a>
 <a class="link" href="#">
   <img src="value" />
 </a>
</div>

ive tried

$('.link').mouseover(function () {
    var adres = ('.link a:first-child').attr('src'); 

but it dosnt workout


Solution

  • $('.link').mouseover(function() {
         var adres = $('img',this).attr('src');
    });