Multiple/repeat .replace on one page
- by Kenneth B
I've made a script which copies the ALT-tag of an image and puts it into a SPAN. It also formates the information devided by a hyphen. It works like a charm, but only with one image.
Further more, I would like it to wrap a div around the image, to prevent unnecessary markup, as I have now. Any ideas is much appreciated... :-)
Script that works now:
HTML:
<div id="hoejre">
<p><span class="alignright"><img src="tommy_stor.jpg" alt="Name - Title" width="162" height="219" /><span></span></span></p>
</div>
jQuery:
var alt = $("#hoejre p span img").attr("alt");
$('#hoejre p span span').html("<strong>" + alt.replace("-", "</strong> <em>") + "</em>");
Output:
<span class="alignright"><img height="219" width="162" alt="Name - Title" src="tommy_stor.jpg"><span><strong>Name </strong> <em> Title</em></span></span>
How do you I repeat the effect on several images, with different information within?
P.S.: I really love this forum. I have used several other forums for this kind of questions, but this one is by far the most professional.