Multiple/repeat .replace on one page

Posted by Kenneth B on Stack Overflow See other posts from Stack Overflow or by Kenneth B
Published on 2010-03-15T17:44:16Z Indexed on 2010/03/15 17:59 UTC
Read the original article Hit count: 257

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui