niche Posted May 2, 2012 Share Posted May 2, 2012 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 More sharing options...
justsomeguy Posted May 2, 2012 Share Posted May 2, 2012 Remove the [0], getElementById returns a single element instead of an array. 1 Link to comment Share on other sites More sharing options...
thescientist Posted May 2, 2012 Share Posted May 2, 2012 as demonstrated in the tutorialshttp://www.w3schools.com/jsref/met_doc_getelementbyid.asp 2 Link to comment Share on other sites More sharing options...
Don E Posted May 2, 2012 Share Posted May 2, 2012 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; 1 Link to comment Share on other sites More sharing options...
niche Posted May 2, 2012 Author Share Posted May 2, 2012 Thanks to justsomeguy, thescientist, and DonE for all their help. Link to comment Share on other sites More sharing options...
Ingolme Posted May 2, 2012 Share Posted May 2, 2012 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 More sharing options...
Don E Posted May 2, 2012 Share Posted May 2, 2012 I'm not too familiar with XML. So then basically this is correct: document.getElementById('here')[0].appendChild(div); ? Link to comment Share on other sites More sharing options...
dsonesuk Posted May 2, 2012 Share Posted May 2, 2012 document.getElementById('here')[0].appendChild(div); document.getElementById targets a unique id ref, so there would/should never be more than one, so using [n] to target another is pointless. Link to comment Share on other sites More sharing options...
eTianbun Posted May 2, 2012 Share Posted May 2, 2012 (edited) 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 May 2, 2012 by eTianbun 1 Link to comment Share on other sites More sharing options...
Don E Posted May 3, 2012 Share Posted May 3, 2012 (edited) 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 May 3, 2012 by Don E Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now