Sam Collett schrieb:
> You will have to use each:
>
> $('.captimg').each( function() {
> $(this).after('<p>' + this.title + '</p>');
> });
Yes, so let's combine this with applying the width and make a little
plugin out of it, so that you can reuse it easily on your whole site:
// Plugin to create an image caption from the title on the fly
jQuery.fn.imgCaption = function() {
return this.each(function() {
var img = $('img', this);
$('<p>' + img.attr('title') + '</p>').css({width: img.width() +
'px'}).appendTo(this);
});
};
// Usage
$('div.image').imgCaption();
HTML:
<div class="image">
<img src="myimage.jpg" width="250" height="350" alt="Image alt"
title="Image title" />
</div>
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/