JSFiddle - React, Tailwind, and code Playground
by skram
HTML
<a href="/post.php?p=100">
<img src="http://www.placehold.it/100x100" />
</a>
<a href="/post.php?p=660">
<img src="http://www.placehold.it/100x100" />
</a>
<a href="/post.php?p=32">
<img src="http://www.placehold.it/100x100" />
</a>
JavaScript
// I want to be able to figure out a way with jQuery, to take the value of 'P' from the parent link (100, 660, 32) and then change the image src from "placehold.it" to "/100.jpg" if at all possible?
$('a > img').each ( function (index) {
var link_href = $(this).parent().attr('href');
link_href = link_href.slice(12); //will give you the number
var img_src = this.src;
img_src = img_src.substring(0, img_src.lastIndexOf('/') + 1) + link_href + '.jpg';
this.src = img_src;
});