<div class="otherProducts">
<a href="http://metroplastasansor.bilginet.com/wp-content/uploads/2014/11/hidrolik-tampon-metroplast-asansor-41943-390057037-b.jpg" class="otherLink"><img src="http://metroplastasansor.bilginet.com/wp-content/uploads/2014/11/hidrolik-tampon-metroplast-asansor-41943-390057037-b.jpg" class="productThumb"></a>
<a href="" class="otherLink"><img src="" class="productThumb"></a>
<a href=""><img src="" class="productThumb"></a></div>
How can I add rel="prettyPhoto[gallery]" to a with jquery? Only links with not empty src!
You can use
.filter()
.I've selected all images withing
.otherProducts
. I then pass a function to filter than will return true if thesrc
attribute is truthy and false if it has a falsy (blank) value.Then use
.attr()
to change therel
attribute for the closest<a>
s to the remaining selections:JSFiddle