insertAdjacentHTML Method 
Author Message
 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



Sat, 10 Feb 2001 03:00:00 GMT  
 insertAdjacentHTML Method
Your pretty close.  The document collection automatically contains certain
items even if they don't have ID's or even exist in a page (BODY, TITLE,
HTML) so your code would be this:

document.body.insertAdjacentHTML('afterBegin,'form');

Quote:

>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



Sat, 10 Feb 2001 03:00:00 GMT  
 insertAdjacentHTML Method
Ah that works just fine, I don't know why I never tried it that way.  Thanks
for replying!!

-Network :)

Quote:

>Your pretty close.  The document collection automatically contains certain
>items even if they don't have ID's or even exist in a page (BODY, TITLE,
>HTML) so your code would be this:

>document.body.insertAdjacentHTML('afterBegin,'form');



Sat, 10 Feb 2001 03:00:00 GMT  
 insertAdjacentHTML Method
I just noticed something interesting about document.body as an object.  It
indeed requires that the body have an ID="" or it will always fail (at least
in insertAdjacentHTML's case).  Im not suprised, though, because since ive
been looking into this for a while I can understand why, it makes sense.
Anyways theres some food for thought :)

-Network



Sat, 10 Feb 2001 03:00:00 GMT  
 insertAdjacentHTML Method
No, I don't believe this is true

Quote:

>I just noticed something interesting about document.body as an object.  It
>indeed requires that the body have an ID="" or it will always fail (at
least
>in insertAdjacentHTML's case).  Im not suprised, though, because since ive
>been looking into this for a while I can understand why, it makes sense.
>Anyways theres some food for thought :)

>-Network



Sat, 10 Feb 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. write script into another frame with innerHTML/insertAdjacentHTML

2. insertAdjacentHTML and removeChild

3. insertAdjacentHTML Questions...

4. HELP: InsertAdjacentHTML Problem

5. insertadjacenthtml of object to trigger autodownload...

6. insertAdjacentHTML

7. Invalid target element for this operation / insertAdjacentHTML

8. Cross Browser insertAdjacentHTML() ??

9. using asp var in "insertAdjacentHtml"

10. VB call to JScript method returns method's source

11. Problems with calling methods

12. document.all method works only on multiple objects ?

 

 
Powered by phpBB® Forum Software