Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a pop up menu within a page called by ajax
    primarykey
    data
    text
    <p>I've been trying to create a button within a php page called by ajax function that pops up a menu when clicked for quite some time but I can't seem to figure it out. The php page is posted under a div called cbox through an ajax method named postAll:</p> <pre><code>&lt;script src="jquery-1.7.1.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="jquery-latest.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function toggleElement(id) { var element=document.getElementById(id); if(element.style.display=="block") { element.style.display="none"; } else { element.style.display="block"; } } function postAll() { if(String(window.location).indexOf("?")==-1) { var location=window.location.href; } else { var location=window.location.href.substring(0,window.location.href.indexOf("?")); var clength=(window.location.href.length-1)-(window.location.href.indexOf("currentpage"))-11; var currentpage=window.location.href.substr(window.location.href.length-clength,clength); } xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("cbox").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","dynamic.php?location="+location+"&amp;currentpage="+currentpage,true); xmlhttp.send(); } $(document).ready(function() { document.getElementById("option").addEventListener("click",function(){alert("Success");}); postAll(); }); &lt;/script&gt; </code></pre> <p>I've tried using addEventListener but I'm not sure I'm using that correctly. I've also tried using the following code but it didn't work either:</p> <pre><code>$("#cbox").delegate("a","click", function() { toggleElement('option_toggle'); }); $("#cbox").on("click", "a", function() { toggleElement('option_toggle'); }); </code></pre> <p>For the .on method I got an uncaught type error as well. Here's the actual button I'm trying to get to pop up a menu:</p> <pre><code>&lt;div id="option"&gt;&lt;p&gt;&lt;a href="#"&gt;&lt;img class="select" src="cog.png"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt; &lt;div id="option_toggle" style="display:none;"&gt; Random Text &lt;/div&gt; </code></pre> <p>Any help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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