Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Zmiana kolejności elementów
Balon
post
Post #1





Grupa: Zarejestrowani
Postów: 422
Pomógł: 0
Dołączył: 14.12.2005
Skąd: Wałbrzych

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


Mam takie coś
  1. <div>
  2. <div id="1">text1</div>
  3. <div id="2">text2</div>
  4. <div id="3">text3</div>
  5. </div>


W jaki sposób zmienić kolejność divów na 3,1,2 ? CHodzi mi oczywiście o sposób w javascripcie (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
tommy4
post
Post #2





Grupa: Zarejestrowani
Postów: 288
Pomógł: 12
Dołączył: 2.12.2005

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


hm

  1. document.getElementById("1").id = "t3";
  2. document.getElementById("3").id = "t2";
  3. document.getElementById("t3").id = "3";
  4. document.getElementById("2").id = "1";
  5. document.getElementById("t2").id = "2";


Jeśli chodzi ci o zamienienie kolejności id (poza tym id nie może zaczynać się od liczby [wg. w3c]).

Jeśli chodzi ci o zamianę tekstów to wystarczy tylko:

  1. document.getElementById("1").id = "text 3";
  2. document.getElementById("2").id = "text 1";
  3. document.getElementById("3").id = "text 2";


Lub bardziej dynamicznie:
  1. var text1 = document.getElementById("1").innerHTML;
  2. var text2 = document.getElementById("2").innerHTML;
  3. var text3 = document.getElementById("3").innerHTML;
  4.  
  5. document.getElementById("1").innerHTML = text3;
  6. document.getElementById("2").innerHTML = text1;
  7. document.getElementById("3").innerHTML = text2;


Ten post edytował tommy4 31.05.2007, 06:21:09
Go to the top of the page
+Quote Post

Posty w temacie


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: 9.10.2025 - 11:30