0

I'm writing a template engine, which generates the entire HTML file by Javascript. However, after I generate the script tag of JQuery, the JQuery syntax doesn't work. But I found that if the HTML file is static, everything works. I have a line of code in a Javascript to generate the JQuery script tag:

input = input.replaceAt(headTagPos,headTagPos+5,"<head><script src='http://fyp-ivanhoe0523.c9users.io/rapid/jquery-3.1.1.min.js'></script><script>"+script+"</script><style>"+style+"</style>");

After that, the HTML will be like this after being rendered: screenshoot

Everything about JQuery is not working here even the code looks fine.

Ivanhoe Cheung
  • 80
  • 2
  • 10
  • http://stackoverflow.com/questions/5235321/how-do-i-load-a-javascript-file-dynamically – ryanlutgen Mar 06 '17 at 03:34
  • 1
    Its not about `jquery` not working.. Try executing the above code in console once the page is loaded and your elements are loaded.. I feel this is specific to `event delegation` issue. Instead of `$("#slide").click` try replacing it with `$(document).on('click','#slide',function(){...})`.. This should probably work... – Guruprasad J Rao Mar 06 '17 at 03:44
  • I tried both solution but still not working, I copy the same code to W3School and everything works fine, it's just doesn't work when it is generated dynamically. http://imgur.com/do0fPd2 – Ivanhoe Cheung Mar 06 '17 at 04:32

0 Answers0