i have this scenario:
<img class="prev" data-modal-img-src="asd"/>
<span></span>
<img class="next"/>
now on cllick i want to get the .prev img element src attr, and i do:
$(function(){
$('span').bind('click',function(){
var _img_src = $(this).prev('img').attr('data-modal-img-src');
alert(_img_src);
});
});
it doesn’t works as expected, any suggestion?
P.S: do not use -1 like is rayining -1
To get the prev they should have common parent could by
bodytag ordivetc. and you do not have attribute'data-modal-img-src'. You should useoninstead of bind as bind is deprecated. Also usedata()instead ofattr()for data attributes.Live Demo
Using
data()Live Demo