Answer the question
In order to leave comments, you need to log in
Why does the event occur 2 times when the button is clicked?
(function($) {
Drupal.behaviors.postsComments = {
attach: function (context, settings) {
$('.icon_comments').bind('click', function(){
var nids = $(this).closest('.mainlist-item').attr('about').split('/');
nid = nids[nids.length - 1];
if (!$(this).attr('data-comments')){
$.post(Drupal.settings.basePath + 'lk/comments', {'nid': nid}, nodeDetails);
$(this).attr('data-comments', true).addClass('open');
}else{
$(this).toggleClass('open');
}
});
}
};
......
})(jQuery);
Answer the question
In order to leave comments, you need to log in
Use once, context and read the documentation :$('.icon_comments', context).once().bind('click'
do return false after your code, maybe you have a second event or have .icon_comments nesting
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question