Note that there are some explanatory texts on larger screens.

plurals
  1. POJS events. Only one of the event handler function is being called?
    text
    copied!<p><strong>Hi everybody!</strong> <br/> I have a problem and I have no idea how to fix it!</p> <p>I have a simple HTML page with a button:</p> <pre><code>&lt;input type = "submit" value = "ok" onclick="f1()"/&gt; </code></pre> <p>I also have a script on this page:<br/></p> <pre><code>&lt;script&gt; function f2() { var firstBtn = document.createElement("button"); firstBtn.appendChild(document.createTextNode("firstBtn")); document.body.appendChild(firstBtn); var xmlhttp = CreateRequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { var response = xmlhttp.responseText; document.body.innerHTML += response; } } firstBtn.onclick = function() { alert("inside f2 onclick"); xmlhttp.open("GET","test.php",true); xmlhttp.send(); } } function f3() { var secondBtn = document.createElement("button"); secondBtn.appendChild(document.createTextNode("secondBtn")); document.body.appendChild(secondBtn); var xmlhttp = CreateRequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { var response = xmlhttp.responseText; document.body.innerHTML += response; } } secondBtn.onclick = function() { alert("inside f3 onclick"); xmlhttp.open("GET","test.php",true); xmlhttp.send(); } } function f1() { f2(); f3(); } function CreateRequest() { var xmlhttp; if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();// code for IE7+, Firefox, Chrome, Opera, Safari else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");// code for IE6, IE5 return xmlhttp; } &lt;/script&gt; </code></pre> <p>So now, when I click one of the buttons (firstBtn or secondBtn), another one is not responding to the click event! Does anybody know why?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload