Post Reply 
[PROG] what's up with appendChild
Author Message
Tetris999
..............................

Posts: 2,390.4622
Threads: 298
Joined: 15th Apr 2007
Reputation: -6.7936
E-Pigs: 82.5657
Offline
Post: #1
[PROG] what's up with appendChild
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:
1
2
3
4
5
6
7
8
9
10
11
12
<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>


MY SIG IS FUCKING DEAD
02/08/2012 08:35 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
[PROG] what's up with appendChild - Tetris999 - 02/08/2012 08:35 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: