I have this:
var xmlhttp = new XMLHttpRequest();
function loadXMLDoc(link){
xmlhttp.open("POST", "index.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("link="+link);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("content").innerHTML=xmlhttp.responseText;
$('input',xmlhttp.responseXML).blur(function(){$(this).css("background-color","gray")}).focus(function(){$(this).css("background-color","red")});
//$("#content").append(xmlhttp.responseText);
}
}
}
why is working background changes of inputs if the
$('input',xmlhttp.responseXML).blur(function(){$(this).css("background-color","gray")}).focus(function(){$(this).css("background-color","red")});
is in a function trigger by a click on a button? how on focus and bllur are trigger?
$.ajax()
? – Ian 15 hours ago$.ajax()
? – nnnnnn 15 hours agoxmlhttp.responseXML
isn't aDocument
object, so you can't bind DOM events to elements inside of it. You can overcome this problem by using jQuery (as well as other, not as easy, solutions), which can parse the XML and you can manipulate as you like – Ian 14 hours ago