Forum Moderators: open
I have a rather simple problem that I for some reason (probably because I am new to coding) can not resolve. I have a template which includes all the necessary javascript and css files. I use ajax to fetch content and use innerhtml to insert the content into a div tag (since the content is in html). The content inserted in the div include links with id's, that when clicked, are used to fetch further content via ajax. However, the event that is supposed to be triggered by the click is not occurring, which seems to be due to the fact that the ajax fetched content doesnt appear to recognize the javascript files in the template.
My question is how can I get the newly inserted content to recognize the javascript tags and code in the template?
Any help would be greatly appreciated.
Example:
External (Doesnt Work)
$('getfunction').addEvent('click', function(event){ function hello()...})
<a id="getfunction">
Inline (Works)
<a onclick="javascript: hello(); return false">
Any idea why this may be the case?
I dont understand the rules, you can access the javascript within the head section via dom functions, I dont think you can for script within the body (within script tags) as for the anon functions such as the onclick= stuff you can get to it via element.onclick.
If you have control of all the source, then more all the javascipt into the head section, if you are dealing with random html from some other source life is more interesting.
Welcome to forum.