var acorn = document.getElementById("boxa");
var outputResults = acorn.childNodes;
document.write(outputResults);
My goal is to write all the child nodes within the id=boxa, that is not working ?
var acorn = document.getElementById("boxa");
var outputResults = acorn.childNodes;
document.write(outputResults);
My goal is to write all the child nodes within the id=boxa, that is not working ?
I'm not sure what you're trying to do... here's a JSBin with what you posted and it is creating output, I just don't have any idea what you're grabbing and what result is expected. Maybe some more code would help. Even elaborating on that jsbin would be great^^
I want to write out all the tags within the div=boxa, that's all :)
document.write()
What is written - h1,p, whatever etc :)
this is a crafty way of doing it...
http://stackoverflow.com/questions/1700870/how-do-i-do-outerhtml-in-firefox
function outerHTML(node){
// if IE, Chrome take the internal method otherwise build one
return node.outerHTML || (
function(n){
var div = document.createElement('div'), h;
div.appendChild( n.cloneNode(true) );
h = div.innerHTML;
div = null;
return h;
})(node);
}
so in your case, you can do:
var acorn = document.getElementById("boxa");
var outputResults = acorn.childNodes;
for (var i=0; i<outputResults.length;i++)
document.write(outerHTML(outputResults[i]));
var acorn = document.getElementById("boxa");
var outputResults = acorn.childNodes;
for (var i=0; i<outputResults.length;i++)
document.write(outerHTML(outputResults[i]));
The function you posted is a little advanced for me at this time.
[object nodelist] is the result from the script, that doesn't seem right ?
It all depends on what your actual code looks like (including the HTML).
Printing out [object nodelist] means the value you are passing into the function is an HTML Collection, which tends to be the return from having multiple items that match a get javascript native function (many browsers return collections when you do getElementById("x") where multiple elements have the id "x".
So, it very well could be "right," but without seeing the whole thing or at least the relevant implementation, so we can follow the code directly and see what you are doing.
I want to write out each tag to in order that it's presented in the HTML. First is the ID, second is the H1 iD and so on.
<body>
<div id="boxa">
<h1 id = "header">This is an emergency</h1>
<p>what is going on <span id="goat"></span><p>
<p>Lets all go to the <span id="place"></span></p>
</div>
</body>
Dude, at least read what you're doing. You placed Javascript in the HTML block and HTML in the Javascript block.
Also, those type of websites don't allow the use of document.write()
I'm not sure why.
Try this one, it seems to be what you where trying to do. JS BIN take a look at the console log to see what's happening.
It was a dumb mistake !
The length command, gotta remember that ! Thanks :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.