次のHTMLとjQueryがありますが、正しく機能していません。
HTML
<div class="conversationsMessage">
<img src="images/conversations-message-control-pin.png" id="conversationsMessagePin" class="conversationsMessagePin" />
<img src="images/conversations-message-control-pin-active.png" id="conversationsMessagePinActive" class="conversationsMessagePin" />
</div>
Javascript
$('img.conversationsMessagePin').click(function() {
alert('yep here now...');
if ($('img#conversationsMessagePinActive', this).css('display') == 'none') {
alert('1');
$(this).hide();
$('img#conversationsMessagePin', $(this).closest('div.conversationsMessage')).show();
} else {
alert('2');
$(this).hide();
$('img#conversationsMessagePinActive', $(this).closest('div.conversationsMessage')).show();
}
});
問題は、常にアラート「2」が表示されることです。たとえば、ifステートメントは常にfalseに相当します。私はまた、次のことを試しました-異なるifステートメントで:
$('img.conversationsMessagePin').click(function() {
alert('yep here now...');
if ($('img#conversationsMessagePin', this).is(':visible')) {
alert('1');
$(this).hide();
$('img#conversationsMessagePin', $(this).closest('div.conversationsMessage')).show();
} else {
alert('2');
$(this).hide();
$('img#conversationsMessagePinActive', $(this).closest('div.conversationsMessage')).show();
}
});
どちらも現在は機能していません-誰かが私がここで間違っていることについてのヒントを教えてもらえますか?
ありがとうございました