I want to add my own captions to my images which are the same width as the images. I'm using javascript to obtain the widths of the images, from Get width of specific div and use as another div's height?, except that only works for an individual image, and would require me to set a separate id for each div. Is there an easier way?
The image captions are created by
<img src="myimage.png">
<div class="imgtxt">Caption</div>
<img src="myimage2.png"> <!-- Width set to 80% -->
<div class="imgtxt">Caption2</div> <!-- Div width still at 100% because its the width of the image class -->
and the current javascript is taken from the link above
var imgWidth = $('img').css('width');
$('.imgtxt').css('width', imgWidth);