Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
1  
You're using jQuery, yet you're not using $.ajax()? – Ian 15 hours ago
1  
Could you please explain the desired behaviour more clearly, and explain what is actually happening more clearly? And as an aside, if you're using jQuery anyway why would you not use $.ajax()? – nnnnnn 15 hours ago
1  
Add a library but write your own code for AJAX requests, omg :( – Harry 15 hours ago
By the way, xmlhttp.responseXML isn't a Document 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
add comment (requires an account with 50 reputation)

put on hold as unclear what you're asking by Stephen P, Łukasz Lech, Michael Härtl, Sergio, Blade0rz 13 hours ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking.If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.