Temat: Wywołanie show/hide dla divów w takich samych boxach bez...
Ja widzę że kolega chyba chce tu zrobić prosty mechanizm, który stosuje się najczęściej na stronach typu FAQ.
Niestety opcja z dorzucaniem dynamicznie klasy i później posługiwania się tą klasą przez jquery nie przejdzie.
Podrzucam coś co jakiś czas temu pisałem:
<!-- toggles -->
<div class="toggles">
<ul>
<li>
<a href="#">Click on this title to show/hide it's content</a>
<p class="">
This is tab 1. Aliquam porttitor metus felis. Curabitur euismod porta justo ut mattis. Mauris condimentum ultrices justo, ac suscipit leo tempor eget.
</p>
</li>
<li>
<a href="#">Click on this title to show/hide it's content</a>
<p class="">
This is tab 2. Aliquam porttitor metus felis. Curabitur euismod porta justo ut mattis. Mauris condimentum ultrices justo, ac suscipit leo tempor eget.
</p>
</li>
<li>
<a href="#">Click on this title to show/hide it's content</a>
<p class="">
This is tab 3. Aliquam porttitor metus felis. Curabitur euismod porta justo ut mattis. Mauris condimentum ultrices justo, ac suscipit leo tempor eget.
</p>
</li>
<li>
<a href="#">Click on this title to show/hide it's content</a>
<p class="">
This is tab 4. Aliquam porttitor metus felis. Curabitur euismod porta justo ut mattis. Mauris condimentum ultrices justo, ac suscipit leo tempor eget.
</p>
</li>
</ul>
</div>
<!-- //toggles -->
/* toggles */
$(".toggles > ul > li > a").click(function(){
$(this).parent().parent().children().children("a").removeClass("current");
$(this).parent().parent().find("p").slideUp("normal");
if($(this).hasClass("current")){
$(this).parent().find("p").slideUp("normal");
$(this).removeClass("current");
}
else {
$(this).parent().find("p").slideDown("normal");
$(this).addClass("current");
}
return false;
});
.toggles ul li p {display:none;}
.toggles ul li p.current {display:block;}
aha i staraj się tak nie pisać: slideDown('slow').show(); - bo jedno konstrukcyjnie troszkę się kłóci z drugim: robisz slidedown by coś pokazać a zaraz po tym jeszcze proste show() - czyli dwa razy prawie to samo
Artur Kwiatkowski edytował(a) ten post dnia 18.10.11 o godzinie 21:31