Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [jquery]zmiany klasy po id
trucksweb
post
Post #1





Grupa: Zarejestrowani
Postów: 1 199
Pomógł: 31
Dołączył: 22.03.2004
Skąd: Warszawa

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


czy jest mozliwosc aby zmienic nazwe klasy elementowi po jego wartosci id ?

robie vcos takiego:
  1. var pole = $(this).attr('id');
  2. $(pole).removeClass("kolor");


gdzie pole przyjmuje nazwe id z elementu np. diva, ale juz nie dziala removeClass ? (IMG:http://forum.php.pl/style_emoticons/default/blinksmiley.gif)
Go to the top of the page
+Quote Post
lord_t
post
Post #2





Grupa: Zarejestrowani
Postów: 603
Pomógł: 131
Dołączył: 24.07.2007
Skąd: Górny Śląsk

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


Po podstawieniu pole do
Kod
$(pole).removeClass("kolor");

masz to wywołane tak:
Kod
$('xxx').removeClass("kolor");

a powinno być:
Kod
$('#xxx').removeClass("kolor");



P.S. Może lepiej zrobić tak:
Kod
$(this).removeClass("kolor");
Go to the top of the page
+Quote Post
trucksweb
post
Post #3





Grupa: Zarejestrowani
Postów: 1 199
Pomógł: 31
Dołączył: 22.03.2004
Skąd: Warszawa

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


nie moze uzyc this bo jak go dam to zmieni mi wszedzie gdzie jest ta klasa ktora trzeba zmienic, a mnie interesuja tylko te elementu ktore maja id
Go to the top of the page
+Quote Post
AxZx
post
Post #4





Grupa: Zarejestrowani
Postów: 1 385
Pomógł: 55
Dołączył: 1.03.2005
Skąd: śląsk

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


a nie tak powinno byc
Kod
var pole = $(this).attr('id');
$('#'+pole).removeClass("kolor");

?
Go to the top of the page
+Quote Post
trucksweb
post
Post #5





Grupa: Zarejestrowani
Postów: 1 199
Pomógł: 31
Dołączył: 22.03.2004
Skąd: Warszawa

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


tak, juz poprawilem, ale teraz musze to wszystko zebrac w calos i wyszlo mi cos takiego, co oczywiscie nie dziala (IMG:http://forum.php.pl/style_emoticons/default/dry.gif)
zmienia mi znak - na + ale odwrotnie juz nie chce
i nie wiem dlaczego ale przestala dzialac akcja toggle (IMG:http://forum.php.pl/style_emoticons/default/dry.gif)

  1. $(document).ready (
  2. function()
  3. {
  4. $(".glowna .minus").click(
  5.  
  6. function() {
  7. var pole = $(this).attr('id');
  8. if($(this).attr('class')=='minus')
  9. {
  10. $("#"+pole).removeClass("minus").addClass("plus");
  11.  
  12. $("#ukryj").toggle("fast");
  13. alert(pole);
  14. }
  15.  
  16. }
  17.  
  18. );
  19. $(".glowna .plus").click(
  20.  
  21. function() {
  22. var pole = $(this).attr('id');
  23. if($(this).attr('class')=='plus')
  24. {
  25. $("#"+pole).removeClass("plus").addClass("minus");
  26. $("#ukryj").toggle("fast"); alert(pole);
  27. }
  28.  
  29.  
  30. }
  31.  
  32. );
  33. }
  34. );


zmiana kolor dziala prawidlowo a zbudowana jest na podobnej zasadzie, w dodatku w innym pliku...

Ten post edytował trucksweb 13.10.2008, 23:49:59
Go to the top of the page
+Quote Post
l1em1on1
post
Post #6





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.10.2008

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


naprawde nie rozumiem po co tyle kombinowania...
  1. $(function() {
  2. $(".glowna .minus").click(
  3. function() {
  4. $(this).removeClass("minus");
  5. $(this).addClass("plus");
  6. $("#ukryj").toggle("fast");
  7. alert($(this).attr('id'));
  8. }
  9. });
  10. });

i podobnie dla plus

po kliknieciu na jakis element o klasach glowna i minus

dany element i tylko on co oznacza this...
robi te zmiany klas[html][/html]

Ten post edytował l1em1on1 16.10.2008, 11:17:18
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 21:48