Menu
I have a node I created, I want to assign it to document.body (so its the only node)…
but I get this error:
Node cannot be inserted at the specified point in the hierarchy
file:///C:/Documents%20and%20Settings/chris/Application%20Data/Mozilla/Firefox/Profiles/oedpmbdl.default/gm_scripts/hdimages_displayonlyimag/hdimages_displayonlyimag.user.js
Line 19
code@19: document.body = CreatedIMG;
<i>
</i> var CreatedIMG = document.createElement("img");
CreatedIMG.setAttribute('src', Found_INPUT[i].value);
document.body.innerHTML = "<img src="" + Found_INPUT[i].value + "">";
<i>
</i>var CreatedIMG = document.createElement("img");
CreatedIMG.setAttribute('src', Found_INPUT[i].value);
document.body.appendChild(CreatedIMG);
To replace the body tag with an image tag would be utterly pointless.well that only appends the image to the HTML body.[/quote]So does your innerHTML method.
edit: and you are wrong, the browser should still "parse" the img tag even without the body tag.[/quote]You're at the point where you'll need to understand the distinction between a tag and an element. The body [i]element[/i] is always there, even if the tags were omitted. And when you're working with the DOM, you're manipulating elements, not tags, and there must always be a body element. Declan was right.
So does your innerHTML method.[/quote]
You're at the point where you'll need to understand the distinction between a tag and an element. The body [i]element[/i] is always there, even if the tags were omitted. And when you're working with the DOM, you're manipulating elements, not tags, and there must always be a body element. Declan was right.[/QUOTE]
lol, this is HTML, not XHTML. Try it yourself, open up notepad and put html, header and a SRC tag between the closing head and closing HTML, it will work.[/quote]Like I said, you need to understand the distinction between an element and a tag. You clearly don't.
My method replaces all HTML with my SRC tag leaving only a image on the website while his method only appends the image to the website....[/quote]Ahh, I see now. You misspoke in your first couple posts. You don't want to replace the body node (in fact you cant, which is what everyone was trying to tell you), you really want to replace the body [i]content[/i].
Like I said, you need to understand the distinction between an element and a tag. You clearly don't.
[url=http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.1]HTML 4.01 spec, section 3.2.1 Elements[/url]
Pay special attention to the note at the end of the Elements section. It says the same as I did almost exactly.
[/quote]
Ahh, I see now. You misspoke in your first couple posts. You don't want to replace the body node (in fact you cant, which is what everyone was trying to tell you), you really want to replace the body [i]content[/i].
Using the DOM methods, you would need to loop through the body's children and remove each one, then append the image node. (If you don't need to manipulate the page any further after this point, then innerHTML would certainly seem the simpler solution.)[/QUOTE]
var CreatedIMG = document.createElement("img");
CreatedIMG.setAttribute('src', Found_INPUT[i].value);
document.body.appendChild(CreatedIMG);
is the standard way to do it:document.body.innerHTML = "<img src="" + Found_INPUT[i].value + "">";
is the non-standard way, they do the exact same thing.<img>
that has an attribute of src, there is no src element.<i>
</i>var el = document.body;
while (el.firstChild) {
document.removeChild(el.firstChild);
}
var CreatedIMG = document.createElement("img");
CreatedIMG.setAttribute('src', Found_INPUT[i].value);
document.body.appendChild(CreatedIMG);
your method threw the image at the very bottom of the page, 100% not what I wanted/needed. To make your method work id have to remove all child elements from body first (both Jeff Mott & rnd me said the same thing).
edit: yeah using that loop is wasted CPU cycle when innerHTML does right away.[/QUOTE]
<i>
</i>function clearNodeContent(node){
while(node.hasChildNodes()){
node.removeChild(node.childNodes[0])
}
}
[B]document.body[/B] is not always a precise referring. It depends on the browser type and on the DOCTYPE used. I suspect the that the standard DOM reference [B]document.getElementsByTagName('body')[0][/B] would be a better option.[/QUOTE]
0.1.9 — BETA 6.16