i have simple html that looks like this :
<div class="img">
<a target="_blank" href="kl_big.htm" id="turn-of-cloth-01_lg">
<img src="images/galery/turn-of-cloth-01_lg.jpg" width="110" height="90" />
</a>
<div class="desc">Add a description of the image here</div>
</div>
i have like 20 sets of this div with different ids , now the href id im gtting with this
$(document).ready(function(){
$('a').click(function (event){
event.preventDefault();
var linkID =$(this).attr("id");
});
});
i dont know what is the img object id , but i need to get its src value .
i tried with Jquery like this :
var imgSrcVal = $(this).siblings("img").attr("src");
but with out result , also tryied inside the click event but again with no results :
imgSrcVal = this.nextSibling.src;
what im doing wrong here ?
The
<img>is not a sibling, it’s a child of the anchor.Try this instead:
Simple JSFiddle demo.