var answerClones = {}; $("[data-answer_id]").each(function(i, el){ answerClones[$(el).data("answer_id")] = $(el).clone(true); }); $("[data-answer_id]:eq(0)").replaceWith(answerClones[82272991]); $("[data-answer_id]:eq(1)").replaceWith(answerClones[82272988]); $("[data-answer_id]:eq(2)").replaceWith(answerClones[82272989]); $("[data-answer_id]:eq(3)").replaceWith(answerClones[82272990]); (function() { jQuery(".voting>div").removeClass("dis"); jQuery(".voting>div").css({"cursor": "pointer"}); jQuery(".voting>div").off(); jQuery(".voting>div").show(); jQuery(".voting>div").each(function(i) { $(this).html($(this).data("text")); switch (i%2) { case 0: $(this).click(function() { $.getScript("/api/vote_answer.php?id=" + $(this).parent().data("vote") + "&q_id=7405189&" + Math.random()); }); break; case 1: $(this).click(function() { $.getScript("/api/vote_answer.php?id=" + $(this).parent().data("vote") + "&q_id=7405189&useless=1" + Math.random()); }); break; } }); const obj = {"82272991":{"c_thanks":1,"c_useless":0,"voted_thanks":false,"voted_useless":false}} for(let id in obj) { if (obj[id].c_thanks) { $("[data-vote='"+id+"']>div:eq(0)").html($("[data-vote='"+id+"']>div:eq(0)").data("text") + " ("+obj[id].c_thanks+")"); } if(obj[id].voted_thanks) { $("[data-vote='"+id+"']>div:eq(0)").addClass("dis"); //$("[data-vote='"+id+"']>div:eq(1)").off(); $("[data-vote='"+id+"']>div:eq(1)").css({"display": "none"}); } if (obj[id].c_useless) { $("[data-vote='"+id+"']>div:eq(1)").html($("[data-vote='"+id+"']>div:eq(1)").data("text") + " ("+obj[id].c_useless+")"); } if(obj[id].voted_useless) { $("[data-vote='"+id+"']>div:eq(1)").addClass("dis"); //$("[data-vote='"+id+"']>div:eq(0)").off(); $("[data-vote='"+id+"']>div:eq(0)").css({"display": "none"}); } } }());