Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 28th, 2005, 12:55 PM
Registered User
Join Date: Jun 2005
Location: , Alabama, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help accessing specific nodes

I'm currently reading the "[u]Professional JavaScript for Web Developers</u>" book by Nicholas C Zakas. In page 171 he talks about how to access specific nodes (he is talking about the DOM) and he shows a way on how to get to them using the tag name. Anyway, this is the code that I'm having trouble with:

        <title>DOM Example</title>
        var oPs = document.getElementsByTagName("p");
        var oImgsInP = oPs[0].getElementsByTagName("img");
        <p style="color:red" id="p1">
        <img src="images/donramon.jpg" name="something" />

        <input type="button" value="show the tag" />
I keep getting the "oPs.1 is null or not an object" and I am copying the code exactly as it is in the book, can anyone help please?
Reply With Quote
  #2 (permalink)  
Old June 29th, 2005, 04:49 AM
Friend of Wrox
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post

The error is occurring because the script is running before the page is built & the document content therefore is not available.
Try changing the script to...
window.onload = function(){
    var oPs = document.getElementsByTagName("p");
    var oImgsInP = oPs[0].getElementsByTagName("img");


Reply With Quote
  #3 (permalink)  
Old June 29th, 2005, 09:45 PM
Registered User
Join Date: Jun 2005
Location: , Alabama, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks, I didn't ever think about that... I'm a JavaScript beginner trying to become a JavaScript Expert so that might have something to do with the problem.:D
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing specific Nodes Krippers XSLT 3 November 6th, 2008 05:38 AM
To Select a specific nodes from XML vkommera XSLT 4 June 27th, 2008 03:39 PM
Accessing nodes contained in a variable geoGregory3 XSLT 2 March 12th, 2008 02:57 PM
Accessing higher level nodes from a template mikeymikey XSLT 3 January 3rd, 2008 09:14 PM
problem accessing nodes using document() and id() siris phi XSLT 3 April 12th, 2007 11:05 PM

All times are GMT -4. The time now is 12:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.