one click, two 'click' event fired
- by Toni Michel Caubet
I just want to toggle some elements when a link is clicked:
This is how i am trying (But i don't really think that it matters much for this question what's inside the event function callback):
/* mostrar exceso de comentarios a peticion del usuario*/
$('.toggleComments').click(function(){
console.log('.toggleComments');
if($(this).parents('.helpContent').find('.commentHideble:visible').length > 0){
$(this).text('+ <?=get_texto_clave('show_old_comments')?>').removeClass('toggleCommentsActive').append(' ('+$(this).parents('.helpContent').find('.commentHideble:not:visible').length+'+)');
}else{
$(this).text('- <?=get_texto_clave('hide_old_comments')?>').addClass('toggleCommentsActive');
}
$(this).parents('.helpContent').find('.commentHideble').slideToggle(100);
});
I even tried a boolean but gave me same result
/* mostrar exceso de comentarios a peticion del usuario*/
var ctoggle = false;
$('.toggleComments').click(function(){
if(ctoggle == false){
ctoggle = true;
console.log('.toggleComments');
if($(this).parents('.helpContent').find('.commentHideble:visible').length > 0){
$(this).text('+ <?=get_texto_clave('show_old_comments')?>').removeClass('toggleCommentsActive').append(' ('+$(this).parents('.helpContent').find('.commentHideble:not:visible').length+'+)');
}else{
$(this).text('- <?=get_texto_clave('hide_old_comments')?>').addClass('toggleCommentsActive');
}
$(this).parents('.helpContent').find('.commentHideble').slideToggle(100);
ctoggle = false;
}
});
Why the log is being fired twice by click?