Question

$(function() {
    $("table.section thead").click(function() {
      if ($(this).next("table.section tbody").style.display == "block"){
         $(this).next("table.section tbody").slideUp("slow");
      }
      if ($(this).next("table.section tbody").style.display == "none"){
         $(this).next("table.section tbody").slideDown("slow");
      }
    });
});

Je ne sais pas comment atteindre cet objectif, toute aide serait très apprécié.

Mise à jour:

Je tentais d'utiliser la fonction suivante.

$(function() {
    $("table.section thead").click(function() {
    $(this).next("table.section tbody").slideToggle("slow");

    });
});

qu'il me donne un problème, (quand il tHead l'effondrement et vous cliquez dessus, il se dilate et s'effondrer là encore, il serait toujours effondrement). Voilà pourquoi je suis en train d'obtenir la fonction en haut.

Était-ce utile?

La solution

l'aide du sélecteur visible dans ce cas:

$(function() {
    $("table.section thead").click(function() {
      var body = $(this).next("table.section tbody");
      if (body.is(":visible"))
         body.slideUp("slow");
      else
         body.slideDown("slow");
    });
});

Mais sans doute beaucoup plus simple il suffit d'utiliser .slideToggle() comme ceci:

$(function() {
    $("table.section thead").click(function() {
      $(this).next("table.section tbody").slideToggle("slow");
    });
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top