Reputation: 15992
I have a div element like this:
<div id="test">
<img src="..."/>
<img src="..."/>
<img src="..."/>
<img src="..."/>
</div>
What I want to do is first to make all the images having the same height, then calculate the sum of their new widths. I tried this :
window.onload = function() {
var width = $(window).width(), totalwidth=0;
$('#test img').height('200px');
$("#test").each(function() {
totalwidth += $("#test img").attr("width");
});
alert(totalwidth);
}
But the alert returns NaN
. What should I do ?
Upvotes: 0
Views: 420
Reputation: 20199
Try
$("#test img").each(function() {
totalwidth += $(this).width();
});
Upvotes: 6