myskif
@myskif
Верстальщик

Как починить document on click if else?

Есть скрипт, который нормально работает:

$(".provider_result_content_analog .provider_result_item_short .provider_result_item_element_more .count span").on('click', function() {
	if ($(this).parents('.provider_result_item').hasClass('provider_result_item_short')) {
		$(this).parents('.provider_result_item').removeClass('provider_result_item_short', 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element').animate({height: 'show'}, 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element_hiden').show();
		$(this).parents('.provider_result_item').find('.count span').hide();
		$(this).parents('.provider_result_item').find('.opened').show();
	}
	else {
		$(this).parents('.provider_result_item').addClass('provider_result_item_short', 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element').animate({height: 'hide'}, 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element_hiden').hide();
		$(this).parents('.provider_result_item').find('.count span').show();
		$(this).parents('.provider_result_item').find('.opened').hide();
	}
});


Но если обернуть в $(document).on('click') , то то что в конструкции else не отрабатывает
$(document).on('click', ".provider_result_content_analog .provider_result_item_short .provider_result_item_element_more .count span", function() {
	if ($(this).parents('.provider_result_item').hasClass('provider_result_item_short')) {
		$(this).parents('.provider_result_item').removeClass('provider_result_item_short', 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element').animate({height: 'show'}, 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element_hiden').show();
		$(this).parents('.provider_result_item').find('.count span').hide();
		$(this).parents('.provider_result_item').find('.opened').show();
	}
	else {
		$(this).parents('.provider_result_item').addClass('provider_result_item_short', 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element').animate({height: 'hide'}, 200);
		$(this).parents('.provider_result_item').find('.provider_result_item_element_hiden').hide();
		$(this).parents('.provider_result_item').find('.count span').show();
		$(this).parents('.provider_result_item').find('.opened').hide();
	}
});


Подскажите в чем проблема
  • Вопрос задан
  • 42 просмотра
Пригласить эксперта
Ответы на вопрос 1
PavelMonro
@PavelMonro
jQuery(document).delegate('.provider_result_content_analog .provider_result_item_short .provider_result_item_element_more .count span', 'click', function() {

}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы