
insertAdjacentHTML Method
If you don't need an explanation of why I need what I'm doing, the questions
is in the last paragraph...
My primary objective is to insert a (invisible/hidden) FORM into an HTML
page dynamically in jscript, inserting it anywhere in the body, and directly
after the body tag seemed to be most convenient. The only way I can see to
do this is to use the "insertAdjacentHTML" method (if you know of an easier
way, please let me know!). I came to the conclusion that inserting the HTML
directly after the BODY tag would probably be the easiest way to do it.
Well I learned that for this to be true that the body tag must have an ID
tag for this to work, because "document.body" doesn't consists of the entire
body, and not the body tag itself (right?). If the body doesn't have an id
tag, "document.body.id" will return blank, and then insertAdjacentHTML won't
work with that. But the problem goes a little farther for that. Assuming
that the body tag does have an id (it is not pre-defined, and can be
different over a wide range of HTML documents so I have to retreive it in
the code itself), the return value of "document.body.id" is a property, and
not an object, which is incompatible with insertAdjacentHTML. The text
value returned with alert() is the exact value that I do need as an object,
and if i replace the tag by hand it works fine.
So my questions is, how do I get the "object" value of my <BODY> tag. Not
the entire body, but i need to reference the tag itself as an object. Or is
there a better way to insert HTML in a document without requiring
pre-defined IDs or variables? Example:
document.body.id.insertAdjacentHTML("AfterBegin", "<INPUT NAME='generic'
TYPE='HIDDEN' VALUE='some value'>");
wont work.
Thanks
-Network