div の子要素を数えて、結果に応じて JS で CSS を変更したいと考えています。
これが私のコードです:
<div id="images" class="images">
<img id="imageItem" class="imageItem" src="http://www.foreclosurelistings.com/images/resources/los-angeles-ca/living-los-angeles.jpg" alt="Scrap image" />
<img id="imageItem" class="imageItem" src="http://www.foreclosurelistings.com/images/resources/los-angeles-ca/living-los-angeles.jpg" alt="Scrap image" />
</div>
JQuery:
count = $("#images img").length;
alert(count); //this alert has to be removed when if statement works
if (count == 2) {
document.getElementById(imageItem).style.width = '200px';
}
count 変数の結果をアラート ボックスで表示すると、それは正しいので、JQuery は子要素 (div 画像内の画像) を正しくカウントします。しかし、if ステートメントは機能しません。
これを機能させるには、私のコードはどのように見えるべきですか?