Endless Paradigm

Full Version: [PROG] what's up with appendChild
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was just doing a little messing around with javascript and I got onto the topic of inserting nodes into the DOM. Basically, I used appendChild on the body element, appending a p element. Thing is, when you view the source of the page, the source page doesn't register that a p element was added to the page, yet you can clearly see a paragraph element on the display page. Why is that? It's confusing since you can't tell if your element was successfully added or not.

I'm guessing that it has something to do with the page being loaded first and the script being second.

Here's the code/page

Code:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
</body>
<script type="text/javascript">
var x = document.createElement("p");
x.textContent = "blahhhhh";
document.body.appendChild(x);
</script>
</html>

Yes you're right. Viewing the source file will show you the page your browser downloaded.

Use a proper DOM inspector which will show you the page as you see it - most browsers have them integrated now, just hit F12.
Reference URL's