var test = document.createElement("p"); test.setAttribute("id","testing"); document.getElementById("body_main").appendChild(test); new Ajax.Request("test.php", { onSuccess: function(response) { document.getElementById("testing").setAttribute("value","testing..."); }, onFailure: function(response) { alert("fail"); } }); alert(document.getElementById("testing").getAttribute("value"));