I'd like to check every attribute src of the image that has class .sogreen
that has a unique prefix on the start of the name or anywhere in the name. After that, it will find the img
element that has a title
attribute that has the same prefix on the first image that we get, and then insert that image below the first image.
HTML
<div class="original">
<img src="pref1-awesome.png" class="img-responsive sogreen">
<img src="pref99-awesome.png" class="img-responsive sogreen">
<img src="pref44-awesome.png" class="img-responsive sogreen">
</div>
<div class="image-entry-to-insert">
<img src="test12.png" title="pref1" class="img-responsive sogreen">
<img src="test4.png" title="pref99" class="img-responsive sogreen">
<img src="test54.png" title="pref44" class="img-responsive sogreen">
</div>
Result Should be:
<div class="original">
<img src="pref1-awesome.png" class="img-responsive sogreen">
<!-- Inserted Item -->
<img src="test12.png" title="pref1" class="img-responsive sogreen">
<!-- End of Inserted Item -->
<img src="pref99-awesome.png" class="img-responsive sogreen">
<!-- Inserted Item -->
<img src="test4.png" title="pref99" class="img-responsive sogreen">
<!-- End of Inserted Item -->
<img src="pref44-awesome.png" class="img-responsive sogreen">
<!-- Inserted Item -->
<img src="test54.png" title="pref44" class="img-responsive sogreen">
<!-- End of Inserted Item -->
</div>
Rough JS Not working:
var imgsrc = $("img.sogreen").attr('src');
console.log(imgsrc);
$(imgsrc).each(function(index, value) {
var imgData = $(this);
$("img").each(function(index2, value2) {
var elementTocounter = $(this).attr('title');
if (imgData == elementTocounter) {
// TODO img insertafter so green
}
});
});
Note: sogreen image might change continuously so for example if the sogreen change the src for an instance the below image should be updated as well.