I am trying to create divs that appear at real time (using jQuery and XML).
After you click that div I want that the user will get redirected to a URL depending on the div he clicked.
the divs are created in for loop and it works fine.
My problem is that each div gets the last value of i which is 5.
for(i=0; i<5;i++){
var div= document.createElement("div");
div.id="conv"+i;
div.innerHTML=conv[i].childNodes[0].nodeValue;
document.getElementById("conv").appendChild(div);
$("#conv"+i).click(function(){
alert(this.id);
var form= document.createElement("form");
form.setAttribute("method","post")
form.setAttribute("action","watch_conv.php");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "chat_room");
hiddenField.setAttribute("value",chat_room[i].childNodes[0].nodeValue);
form.appendChild(hiddenField)
document.body.appendChild(form);
//form.submit();
alert(i);
});
$("#conv"+i).animate({opacity:"show"});
}