Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Klasa dla pierwszych akapitów w bloku
kamil_lk
post 26.09.2012, 16:22:07
Post #1





Grupa: Zarejestrowani
Postów: 325
Pomógł: 33
Dołączył: 31.05.2008

Ostrzeżenie: (0%)
-----


Cześć.

  1. <div id="kontener">
  2.  
  3. <div class="box">
  4. <div class="opis">
  5. <p>Akapit jeden</p>
  6. <p>Akapit dwa</p>
  7. <p>Akapit trzy</p>
  8. <p>Akapit cztery</p>
  9. </div>
  10. </div>
  11.  
  12. <div class="box">
  13. <div class="opis">
  14. <p>Akapit jeden</p>
  15. <p>Akapit dwa</p>
  16. <p>Akapit trzy</p>
  17. <p>Akapit cztery</p>
  18. </div>
  19. </div>
  20.  
  21. <div class="box">
  22. <div class="opis">
  23. <p>Akapit jeden</p>
  24. <p>Akapit dwa</p>
  25. <p>Akapit trzy</p>
  26. <p>Akapit cztery</p>
  27. </div>
  28. </div>
  29.  
  30. </div>


W jaki sposób mogę nadać klasę wszystkim pierwszym akapitom w danych blokach?

Próbowałem w ten sposób, ale nadaje to klasę tylko pierwszemu, którego napotka
  1.  
  2. $(document).ready(
  3. function(){
  4.  
  5. $('#kontener .box .opis p').hide(); //ukrywam wszystkie p
  6.  
  7. $('#kontener .box .opis p:first').show(); // tutaj chciałbym pokazać wszystkie pierwsze akapity
  8.  
  9. }
  10. );
  11.  


Ten post edytował kamil_lk 26.09.2012, 16:22:26
Go to the top of the page
+Quote Post
Greg0
post 26.09.2012, 16:26:23
Post #2





Grupa: Zarejestrowani
Postów: 264
Pomógł: 54
Dołączył: 31.08.2007
Skąd: Tychy

Ostrzeżenie: (0%)
-----


Skorzystaj z http://api.jquery.com/each/
Go to the top of the page
+Quote Post
kamil_lk
post 26.09.2012, 16:40:24
Post #3





Grupa: Zarejestrowani
Postów: 325
Pomógł: 33
Dołączył: 31.05.2008

Ostrzeżenie: (0%)
-----


Możesz pokazać jak to zrobić?

W jq jestem troche zielony.

Próbuję jakoś tak, ale nie bangla
  1. $('#kontener .box .opis p:first').each(function(){
  2. $(this).show();
  3. });
Go to the top of the page
+Quote Post
mccd
post 26.09.2012, 16:41:40
Post #4





Grupa: Zarejestrowani
Postów: 58
Pomógł: 12
Dołączył: 14.01.2011

Ostrzeżenie: (0%)
-----


http://jsfiddle.net/veQzM/

lub samo:

http://jsfiddle.net/veQzM/1/
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 16.06.2025 - 19:23