using innerHTML to run a script
I have a script in the head of the document with the following line:
and I want it to be used to run function foo() in the body:
but it doesn't write anything in console. what is the problem?
possibly one of the weirder attempts at a function call I have seen.
but it's a basic problem: your getElementById runs in the head, which comes before the body
your "txtHint" div gets created in the body. ie, after your script has run
so the code tries to get an element that doesn't exist yet
and it pretty much goes all downhill from there. there may be other conceptual problems with what you are trying to do, but that's the dealbreaker for now.
can I ask why you are trying to do it that way instead of something a little more, uh... normal?
<script> tags created with innerHTML don't work.
If you just want to call foo(), then why don't you just call it directly? Why do you need innerHTML to call it?
If you want to add a script to the page then just use the correct DOM call to create the script tag. It is one of the situations where you must use the DOM rather than innerHTML.
|All times are GMT +1. The time now is 11:54 AM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.