Re: [jQuery] Setting an image caption width

2007-02-14 Thread Sam Collett
On 14/02/07, Seb Duggan [EMAIL PROTECTED] wrote: Not sure I agree on the title attribute not being suitable, but I see your point on the alt. Nevertheless, I want to change this: img src=/myimage.jpg width=250 height=350 alt=Alt text title=Some text I want to use as the caption

Re: [jQuery] Setting an image caption width

2007-02-14 Thread Klaus Hartl
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

Re: [jQuery] Setting an image caption width

2007-02-14 Thread Klaus Hartl
make it: (function($) { $.fn.imgCaption = function() { return this.each(function() { var img = $('img', this); $('p' + img.attr('title') + '/p').css({width: img.width() + 'px'}).appendTo(this); }); }; })(jQuery);

Re: [jQuery] Setting an image caption width

2007-02-14 Thread Seb Duggan
Great stuff, Klaus! The more I learn about jQuery, the more I wish I'd discovered it before! Seb On 14 Feb 2007, at 14:06, Klaus Hartl wrote: make it: (function($) { $.fn.imgCaption = function() { return this.each(function() { var img = $('img', this);

Re: [jQuery] Setting an image caption width

2007-02-13 Thread Kenneth
This should work: $('div.image p').width($('div.image p').prev().width()); Although I am not sure why $(this) would not work; perhaps someone else will know why? On 2/13/07, Seb Duggan [EMAIL PROTECTED] wrote: I've got a number of pictures with captions that will be floated right in the main

Re: [jQuery] Setting an image caption width

2007-02-13 Thread Klaus Hartl
Seb Duggan schrieb: I've got a number of pictures with captions that will be floated right in the main body text. The HTML looks like this: div class=image img src=myimage.jpg width=250 height=350 alt=Image description pA caption for the image/p /div Because the images

Re: [jQuery] Setting an image caption width

2007-02-13 Thread Seb Duggan
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

Re: [jQuery] Setting an image caption width

2007-02-13 Thread Klaus Hartl
Seb Duggan schrieb: 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.

Re: [jQuery] Setting an image caption width

2007-02-13 Thread Seb Duggan
Perfect, Klaus! Thanks, that does exactly what I want it to. Now to rewrite the HTML, so the float div is generated automatically, and the caption is generated from the alt attribute... Seb On 13 Feb 2007, at 21:03, Klaus Hartl wrote: Stupid me, I forgot a return statement (too much

Re: [jQuery] Setting an image caption width

2007-02-13 Thread Klaus Hartl
Seb Duggan schrieb: Perfect, Klaus! Thanks, that does exactly what I want it to. Now to rewrite the HTML, so the float div is generated automatically, and the caption is generated from the alt attribute... The alt attribute should be something different than the caption (and the title