これを試してください:リンク
HTML:
<div class="location-container" Location="Spain">
<div class="text-container">United Kingdom, Spain</div>
</div>
<div class="location-container" Location="United Kingdom">
<div class="text-container">United Kingdom, Spain</div>
</div>
JS
$('.location-container').each(function(){
if( $(this).attr('Location').toString().indexOf("United Kingdom")!=-1) {
$(this).find('.text-container').text(
$(this).find('.text-container').text().replace('United Kingdom','<img src="http://northcyprusfreepress.com/wp-content/uploads/2011/06/flag_icon_uk.gif"/>'));
// $(this).find('.text-//container').html($(thi//s).find('.text-container').text());
}
if($(this).attr('Location').toString().indexOf("Spain")!=-1) {
$(this).find('.text-container').text( $(this).find('.text-container').text().replace('Spain','<img src="http://www.images2.welproma.com/spain_flag_icon.png"/>'));
}
$(this).find('.text-container').html($(this).find('.text-container').text());
});