I have a list of items that can be hidden/unhidden via JS be clicking them. The currently open item is stored in a variable, openActivity
. Only one item can be opened at a time. I want to check in the click() event whether the clicked item is the same as the already opened item, so that it does not do a double-animation of it closing and then opening. I would suspect this to work at first:
if (openActivity == $(this)) alert('hello');
But it does not. I noted this does not work either:
if ($(this) == $(this)) alert('hello'); //never alert()s !
Here's all most relevant code, if it's worth anything to you (you may not have to look at this):
openActivity = null;
$('.activityOuterContainer').click(function () {
if (openActivity !== null) {
if (openActivity == $(this)) alert('hello');
activityExtra(openActivity).slideUp();
activityToggle(openActivity).css('background-position', '0 0');
}
openActivity = $(this);
activityExtra(openActivity).slideDown();
activityToggle(openActivity).css('background-position', '0 -20px');
});
function activityToggle(a) {
return a.closest('.activityOuterContainer').find('.activityToggle');
}
function activityExtra(a) {
return a.closest('.activityOuterContainer').find('.activityExtra');
}
And one of the items:
<div class="activityOuterContainer">
<div class="activityContainer">
<div class="activityFormContainer">
name here
<div class="activityExtra">
<p>extra</p>
</div>
</div>
<div class="activityIsUsed">checkbox here</div>
</div>
<div class="activityToggle"></div>
</div>