J'ai 2 éléments - "span" (nommé "divLikedX") et "a" (nommé "aLikeX"). J'ai le javascript suivant (en cliquant par se produit « a »):Comportement étrange en JavaScript
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');
}
});
};
Si je retire $("#aLike" + CommentID).text('Unlike');
et $("#aLike" + CommentID).text('Like');
chaînes que je reçois le bon comportement. Mais avec ces chaînes il fonctionne correctement seulement les 2 premiers clics, après alert($("#divLiked" + CommentID).is(':visible')) == "true"
toujours. Pourquoi?
pointe: la deuxième ligne peut être remplacé par 'if (CommentID)' –
Ma seule suggestion est de "inspecter l'élément" avec FF ou chrome au début et après chaque clic pour voir quels attributs le div obtient. –
L'un de ces éléments est-il le parent de l'autre? –