This is my code :
jQuery(document).ready(function () {
jQuery(".jlk").live("click", function (e) {
e.preventDefault();
var task = jQuery(this).attr("data-task");
var post_id = jQuery(this).attr("data-post_id");
var nonce = jQuery(this).attr("data-nonce");
var currentClass = $(this).attr('class');
jQuery(".status-" + post_id).html(" ").addClass("loading-img").show();
jQuery.ajax({
type: "post",
dataType: "json",
url: wtilp.ajax_url,
data: { action: "wti_like_post_process_vote", task: task, post_id: post_id, nonce: nonce },
success: function (response) {
jQuery(".lc-" + post_id).html(response.like);
jQuery(".unlc-" + post_id).html(response.unlike);
jQuery(".status-" + post_id).removeClass("loading-img").empty().html(response.msg);
}
});
});
// Other users tooltip
jQuery("span.wti-others-like").live("mouseover", function () {
jQuery(this).children("span").show();
});
jQuery("span.wti-others-like").live("mouseout", function () {
jQuery(this).children("span").hide();
});
});
And I'm trying to add the conditional statement like this :
if (jQuery(".lc-" + post_id).html(response.like)) {
$(".action-unlike-" + post_id + " img").removeClass('opacity-none'); $(".action-like-" + post_id + " img").addClass('opacity-none'); alert('positive');
}
else if (jQuery(".unlc-" + post_id).html(response.unlike)) { $(".action-like-" + post_id + " img").removeClass('opacity-none'); $(".action-unlike-" + post_id + " img").addClass('opacity-none'); alert('negative'); }
But it always alert 'positive' like its not reading my conditions.
How can i accomplish this?
If (response.like == 'true') {do this} else if (response.unlike == 'true') {do this} ?
htmlmethod as a setter returns an object which is a truthy value, so ... . Is that supposed to bejQuery(".lc-" + post_id).html() === response.like?jQuery(".lc-" + post_id).html(response.like)to cause an alert negative.jQuery.fn.htmlreturns the jQuery collection which evaluates totrue, so your condition is always true. What exactly did you want yourifto check for?