Jump to content

HTML DOM/Javascript help


BooKwiznak
 Share

Recommended Posts

Hello forum,Not sure if this is the right place to ask this question, but I was going through the HTML DOM tutorials and came on a 'road block'. I'm in the Node Access section and the last example where they mention using the firstChild property is confusing me a bit. The following example code is :

<html><body><p id="intro">Hello World!</p><script type="text/javascript">x=document.getElementById("intro");document.write(x.firstChild.nodeValue);</script></body></html>

And the output would be: Hello World!Now here is my code:

<html><body><p>Hello World!</p><p>Bye World!</p><script type="text/javascript">x=document.getElementsByTagName("p");document.write(x.lastChild.nodeValue);</script></body></html>

I'm trying to get the output to be: Bye World! The code doesn't work. Am I missing something?

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...