Jump to content

appending id


niche

Recommended Posts

I have a script that I've modified based on:http://www.w3schools.com/php/php_ajax_php.asp I currently have a code that appends an output div to the end of the body:document.getElementsByTagName('body')[0].appendChild(div); I thought I could append the output div to the input form (bottom of yellow div) by giving the form an id and appending it like this:document.getElementById('here')[0].appendChild(div); Except, that's a no go. How do I get the div from the end of the body to the end of the form? If needed, you can see what I'm talking about at:http://www.lincolnsrealdeals.com/temp111b.php

Link to comment
Share on other sites

Just to add: This

document.getElementsByTagName('body')[0].appendChild(div);

.. looks like it would be for XML accessing of elements. Ie:

x = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;

  • Like 1
Link to comment
Share on other sites

Thanks to justsomeguy, thescientist, and DonE for all their help.

Link to comment
Share on other sites

Just to add: This
document.getElementsByTagName('body')[0].appendChild(div);

.. looks like it would be for XML accessing of elements. Ie:

x = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;

All XML DOM methods are correct to use in HTML, as their DOM trees have the same kind of structure.
Link to comment
Share on other sites

I'm not too familiar with XML. So then basically this is correct:
document.getElementById('here')[0].appendChild(div);

No, thats wrong. getElementsByTagName is a method, which returns an array of specified element withing a Node. Almost all DOM objects (non-empty elements) have the method. EXAMPLE:
document.getElementById('div').getElementsByTagName('h1')[0].nodeName;

Edited by eTianbun
  • Like 1
Link to comment
Share on other sites

Thanks for clarifying. When I saw document.getElementsByTagName('h1')[0].nodeName; it looked unfamiliar(saw it in XML recently though) to me as I normally do this instead with that method to access the individual elements :ie:

var div = document.getElementsByTagName('div'); div[0].innerHTML = "Hello"; div[1] innerHTML = "Hello again";

etc

Edited by Don E
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...