Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> jquery dodanie klasy do div'a tylko raz...?
marcus755
post 21.07.2014, 09:47:43
Post #1





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

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


Pytanie,
jak w jquey wymusić, żeby tylko raz dodał mi poniższą klasę, a nie do każdego?

  1. $(".test").find(".podtest").addClass("jakas");
  2.  
  3. <div class="test">
  4. <div class="podtest">
  5. costam
  6. </div>
  7. </div>
  8.  
  9. <div class="test">
  10. <div class="podtest">
  11. costam
  12. </div>
  13. </div>
  14.  
  15. <div class="test">
  16. <div class="podtest">
  17. costam
  18. </div>
  19. </div>
Go to the top of the page
+Quote Post
Pyton_000
post 21.07.2014, 09:48:20
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Kod
.find(".podtest").first().
Go to the top of the page
+Quote Post
Turson
post 21.07.2014, 09:48:54
Post #3





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Kod
$(".test").find(".podtest:nth-child(1)").addClass("jakas");
Go to the top of the page
+Quote Post
marcus755
post 21.07.2014, 09:56:52
Post #4





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

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


to wiem...,
ale jak użyję .first(),
to nie bedzie tak, że zawsze doda mi tylko do pierwszego?

bo ja chciałem zrobić docelowo
coś takiego, że np.
o godz.:
9:00 - dodaje mi klasę .jakaś do pierwszego div'a z klasą .podtest
10:00 - usuwa mi z pierwszego, a dodaje do drugiego
11:00 - usuwa mi z drugiego, a dodaje do trzeciego

jak zrobić?

Ten post edytował marcus755 21.07.2014, 10:03:01
Go to the top of the page
+Quote Post
trueblue
post 21.07.2014, 10:05:51
Post #5





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


Przypisz im jakiś atrybut, np.: data-hour="xx", o danej godzinie sprawdzaj i jeśli się zgadza, to przypisz klasę, pozostałym usuń.


--------------------
Go to the top of the page
+Quote Post
vermis
post 21.07.2014, 10:06:25
Post #6





Grupa: Zarejestrowani
Postów: 279
Pomógł: 56
Dołączył: 3.06.2010
Skąd: Tarnowskie Góry

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


użyj :nth-child(n) lub pobierz podrzędne elementy do tablicy, usuń klasę wszystkim, następnie w pętli znajdź odpowiedni element i potem nadaj mu klasę.


--------------------
Go to the top of the page
+Quote Post
Pyton_000
post 21.07.2014, 10:07:57
Post #7





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Pobierz godzinę, odejmij 8 i wynik wstaw w :nth-child(xxx)
Go to the top of the page
+Quote Post
marcus755
post 21.07.2014, 10:28:42
Post #8





Grupa: Zarejestrowani
Postów: 158
Pomógł: 1
Dołączył: 6.12.2012

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


Pobieram sobie .getTime();
chyba zapomniałem,
ale jak wyciągnąć ze span z klasą .time liczby określające czas,
i powiązać to z .getTime(); w taki sposób żeby dodać i ukrywać klasę?


  1. var start = new Date().getTime();
  2. $(".test").find(".podtest").addClass("jakas");
  3.  
  4. <div class="test">
  5. <div class="podtest">
  6. <span class="time">9:45</span>
  7. </div>
  8. </div>
  9.  
  10. <div class="test">
  11. <div class="podtest">
  12. <span class="time">10:30</span>
  13. </div>
  14. </div>
  15.  
  16. <div class="test">
  17. <div class="podtest">
  18. <span class="time">11:00</span>
  19. </div>
  20. </div>
Go to the top of the page
+Quote Post
trueblue
post 21.07.2014, 10:39:29
Post #9





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


text()


--------------------
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: 28.03.2024 - 11:08