Strange behavior in JavaScript
<p>I have 2 elements - "span" (named "divLikedX") and "a" (named "aLikeX"). I have the following javascript (occurs clicking by "a"):</p>

<pre><code>    function CommentLike(CommentID, aLink) {
        if (CommentID != null &amp;&amp; CommentID &gt; 0)
            $.post("/Home/LikeComment", { CommentID: CommentID },
            function () {
                //alert($("#divLiked" + CommentID).is(':visible'));
                /*alert($(aLink).text());*/if ($("#divLiked" + CommentID).is(':hidden')) {
                    $("#divLiked" + CommentID).show();
                    $("#aLike" + CommentID).text('Unlike');
                } else {
                    $("#divLiked" + CommentID).hide();
                    $("#aLike" + CommentID).text('Like');
                }
            });
        };
</code></pre>

<p>If I remove <code>$("#aLike" + CommentID).text('Unlike');</code> and <code>$("#aLike" + CommentID).text('Like');</code> strings I get the correct behavior. But with these strings it works correctly only first 2 clicks, after it <code>alert($("#divLiked" + CommentID).is(':visible')) == "true"</code> always. Why?</p>
