Looking to ensure that a series of captions have the same width as the images preceding them.
This is the HTML code:
<div class="theparent">
<img src="pic.jpg"/>
<div class="caption">
hello
</div>
<div>
<div class="theparent">
<img src="pic2.jpg"/>
<div class="caption">
hello
</div>
<div>
<div class="theparent">
<img src="pic3.jpg"/>
<div class="caption">
hello
</div>
<div>
Each image has a different width, but I want each caption to match the width of the previous picture. This width may change over time, requiring the use of SetTimeOut.
I've attempted something like this:
function launchcaption() {
var myWidth = $(".theparent img").width();
$(this).next().css( "width", "myWidth" );
}
setTimeout(launchcaption, 10);
Please avoid suggesting CSS solutions, as JavaScript is necessary in this case. Thank you!