1

I have 2 elements - "span" (named "divLikedX") and "a" (named "aLikeX"). I have the following javascript (occurs clicking by "a"):

    function CommentLike(CommentID, aLink) {
        if (CommentID != null && CommentID > 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');
                }
            });
        };

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

6
  • tip: the second line can be replaced by if (CommentID) Commented Sep 28, 2010 at 22:10
  • My only suggestion is to "inspect element" with FF or chrome at the start and after each click to see what attributes the div gets. Commented Sep 28, 2010 at 22:15
  • Is either of these elements the parent of the other? Commented Sep 28, 2010 at 22:17
  • Why FF or Chrome? I have the problem in IE 8.0 Commented Sep 28, 2010 at 22:29
  • no parent of the other. Seems, problem is because this aLink is the same where is clicked. But how to solve.... Commented Sep 28, 2010 at 22:30

1 Answer 1

1

you do not seem to be the only one with the issue : cf http://forum.jquery.com/topic/hidden-visible-broken-in-ie8

The problems seems to append in IE8 when a display:none element has visible elements nearby. This seems to fool the jquery algorithm that detects :visible.

I can advice you to test with a class instead of :visible and :hidden :

if ($("#divLiked" + CommentID).hasClass('like')) {
      $("#divLiked" + CommentID).removeClass('like').show();
      $("#aLike" + CommentID).text('Unlike');
} else {
      $("#divLiked" + CommentID).addClass('like').show();
      $("#aLike" + CommentID).text('Like');
}

I hope this will help you,

Jerome Wagner

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.