I am trying to get the width of some nested image. I have the following HTML code:
<div class="slide" id="Slide1">
<a href="#" title="Some Title" target="_blank">
<img src="images/photo1.jpg" alt="Slide 1" class="slideImg">
</a>
<div class="caption" style="width: 476px">
<h1>Stuff</h1>
<p>Some Stuff Description</p>
</div>
</div>
<div class="slide" id="Slide2">
<a href="#" title="Some Title" target="_blank">
<img src="images/photo.jpg" alt="Slide 2" class="slideImg">
</a>
<div class="caption" style="width: 476px">
<h1>Stuff</h1>
<p>Some Stuff Description</p>
</div>
</div>
And working with jQuery, I want to get the width of each IMG so then I can set (1024px - that width) to the correct "CAPTION DIV" ( <div class="caption">
). Both of this script, are giving me a second image whose width is "0", an impossible thing.
$('.slideImg').each(function(){
alert($(this).width());
});
$('.slide').each(function(){
alert($(this).attr('id'));
alert($(this).find('a').find('img').width());
});
Thanks in advance!