Thanks Klaus.

Yes, I'm using jQuery 1.1.

However, this still doesn't seem to work. Try the sample code with a  
longer caption, and this:

$('div.image p').click( function() {
alert( $(this).width() );
});

Now, clicking the caption will report its actual width. It's not  
being limited to the width of the image...


Seb


On 13 Feb 2007, at 13:59, Klaus Hartl wrote:

> Seb, from the code you supplied the error is that "this" in your
> assignment doesn't refer to the selected p. If you're using jQuery  
> 1.1.
> you can do this:
>
> $('div.image p').css('width', function() { $(this).prev().width 
> (); } );
>
> With a little more semantic HTML (create a relationship between image
> and caption by using a dl)
>
> <dl class="image">
>      <dt><img src="myimage.jpg" width="250" height="350" alt="Image
> description"></dt>
>      <dd>A caption for the image</dd>
> </dl>
>
> the code has to look like:
>
> $('dl.image').css('width', function() { $('img', this).width(); } );
>
> If you don't use jQuery 1.1 you would have to use an each loop, let me
> know if that's the case.
>
>
> -- Klaus
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to