Answer the question
In order to leave comments, you need to log in
How to check for a repeat click?
there is a code, when clicked, the value changes
echo '<div class="like">';
if(какое то условие ){
echo '<div class="Like_act" data-id="'.$posting['id'].'">5</div>';
}else{
echo '<div class="Like_bck" data-id="'.$posting['id'].'">5</div>';
}
echo '</div>';
$(document).ready(function() {
$(".like").bind("click", function(event) {
var linc = $(this);
var dit = $(this).attr("data-id");
$.ajax({
url: "ajaxLike.php",
type: "POST",
data: ("id=" +dit),
dataType: "text",
success: function(result) {
linc.addClass('Like_act');
linc.text(Number(linc.text()) + 1);
}
});
});
});
Answer the question
In order to leave comments, you need to log in
Why not just do
<div class="like__box">
<div class="like"></div>
</div>
$('.like').click(function() {
if($(this).hasClass('Like_act')) {
//... тут ваши Ajax запросы)
} else {
//... тут ваши Ajax запросы)
}
})
Do you have +1 for like_act and -1 for like_bck? Here also check presence/absence of a class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question