Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [js] onclick nie działa, gdy element tworzony przez createlement
Balon
post 22.06.2007, 22:35:48
Post #1





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

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


Tak jak w temacie. Najpierw kombinowałem tak.

Kod
div  = document.createElement("div");
div.className = "greeting";
                    
div1 = document.createElement("div");
div1.className = "greeting_head";
div1.innerHTML = json.greetings[i].nick;
                    
img = document.createElement("img");
img.src = "img/delete.png";
img.onclick = function(){delete_greeting(this);}
div1.appendChild(img);
                    
div.appendChild(div1);
                    
div1 = document.createElement("div");
div1.className = "greeting_body";
div1.innerHTML = json.greetings[i].msg;
div.appendChild(div1);

$('greetings').appendChild(div);


jednak potem sie doczytałem, że jak się odwołam przez ID to będzie działało.


więc zrobiłem tak.

Kod
div  = document.createElement("div");
div.className = "greeting";
                    
div1 = document.createElement("div");
div1.className = "greeting_head";
div1.innerHTML = json.greetings[i].nick;
                    
img = document.createElement("img");
img.id = "d" + json.greetings[i].id;
img.src = "img/delete.png";
img.onclick = function(){delete_greeting(this);}
div1.appendChild(img);
                    
div.appendChild(div1);
                    
div1 = document.createElement("div");
div1.className = "greeting_body";
div1.innerHTML = json.greetings[i].msg;
div.appendChild(div1);
                    
$('greetings').appendChild(div);
$("d" + json.greetings[i].id).onclick = function(){delete_greeting(this);}


Ale o dziwo exclamation.gif to nie działa. Przy wcześniejszych zabawach tworzenie eventu poprzez odwołanie sie przez ID działało.

Co robię źle ?


ps. oczywiście funkcja $ zwraca odwołanie przez document.getElementById()
proszę o pomocc,
pozdrawiam


--------------------
Postura wielka i morda wredna, jestem Balon, kozak z osiedla !
bzdury.pl - Królestwo rozrywki
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: 18.07.2025 - 00:29