Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems to get jquery to work in json rendered html format
    primarykey
    data
    text
    <p>I run a "strip out" version of FB bigPipe and it's working perfect, except the jquery. When I parse the jquery in json format and append to a div tag, the jquery stop working.</p> <p>You can see the "bigPipe" jquery code I use <a href="http://jsfiddle.net/YHVzE/1/" rel="nofollow">here</a></p> <p>The code to get this working is pretty simple. In PHP:</p> <pre><code>$data = array( 'id' =&gt; {div tag ID}, 'content' =&gt; {html content}, 'title' =&gt; {document title}, 'css' =&gt; {...}, 'js' =&gt; {...} ); $output = '&lt;script&gt;Test.render(' . json_encode($data) . ');&lt;/script&gt;'; </code></pre> <p>I think the problem is that I have to add window.addEventListener not to the window itself, but to the div tag I append the content.</p> <p>And here I'm stuck. How do I do this? How do I get this jquery to work in this appended html?</p> <p><strong>Here is a example on how it should work:</strong></p> <p>If you try to run this code from a php file problems occur.Do this:</p> <ol> <li>Put the js code from jsFiddle in a js file and include normaly in the .php file. Make a div tag in the php file and call it "not_working"- Save</li> <li>Make a empty .html document and add a div tag like <code>&lt;div id="test"&gt;Click me&lt;/div&gt;</code> and save. <ol> <li>Make a new js file and name it test.js. Put in this code:</li> </ol></li> </ol> <p>$(function() {</p> <pre><code>$("body").on("click","#test",function(){ alert("You clicked me!!"); }); </code></pre> <p>});</p> <p>Save.</p> <ol> <li><p>In the PHP file, add this: <code>$data = array( 'id' =&gt; "not_working", 'content' =&gt; {LINK and NAME to the HTML file you created!!}, 'title' =&gt; "Test", 'css' =&gt; "", 'js' =&gt; {LINK and NAME to the JS file you created!!}, );</code></p></li> <li><p>Run the .php file, click on the Click me!. </p></li> </ol>
    singulars
    1. This table or related slice is empty.
    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