{"id":253,"date":"2009-11-20T04:33:00","date_gmt":"2009-11-20T04:33:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=253"},"modified":"2009-11-20T04:33:00","modified_gmt":"2009-11-20T04:33:00","slug":"datatable-jquery-plugin-javascript-inside-a-table-cell","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=253","title":{"rendered":"DataTable jQuery Plugin &#8211; JavaScript inside a table cell"},"content":{"rendered":"<p>If the data source is AJAX and the cell has JavaScript, the node is created and assigned directly via nTd.innerHTML=data so any JavaScript code inside the cell won&#8217;t get executed. To correct than you need the custom fnRender for that column.<\/p>\n<p><textarea name=\"code\" class=\"js\"><br \/>\nfnRender: function (o) {<br \/>\n var oTmp = document.createElement(&#8220;div&#8221;);<br \/>\n oTmp.innerHTML = o.aData[5]; \/\/ just to let the browser parse HTML for me<br \/>\n var aScripts = oTmp.getElementsByTagName(&#8220;script&#8221;);<br \/>\n for (var i=0;i < aScripts.length;i++) {\n   \/\/ similar to jQuery core: inject into head, then remove (avoid re-eval)\n   jQuery.globalEval(aScripts[i].text || aScripts[i].textContent || aScripts[i].innerHTML || \"\" );\n   if (aScripts[i].parentNode) { aScripts[i].parentNode.removeChild(aScripts[i]); }\n } \/\/ rof\n return oTmp.innerHTML;\n}\n<\/textarea><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If the data source is AJAX and the cell has JavaScript, the node is created and assigned directly via nTd.innerHTML=data so any JavaScript code inside the cell won&#8217;t get executed. To correct than you need the custom fnRender for that column. fnRender: function (o) { var oTmp = document.createElement(&#8220;div&#8221;); oTmp.innerHTML = o.aData[5]; \/\/ just to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/253"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=253"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/253\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}