Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2003
    Location
    Sydney Australia
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DOM getElementsByTagName

    Hi,

    I'm using the getElementsByTagName method to obtain a customer listing of records. So far so good. However, I also want to reference the child nodes of the customer records.

    ie.
    <customer id="1234" name="Mr Dodd">
    <purchase po="1" value="3.00"/>
    <purchase po="2" value="4.00"/>
    <purchase po="3" value="5.00"/>
    </customer>

    I used getElementsByTagName("customer") to obtain the list of customers, but I'm having trouble referencing the child nodes ie. purchase.

    Does getElementsByTagName("customer") also obtain the child nodes, or only the matching element?

    thanks

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It obtains all 'customer' nodes in the document and puts them in a dynamic collection. However, each of those nodes will in turn contain ways to get at just the 'purchase' nodes that belongs to it, either by the childNodes collection if you want all child nodes, or by the method getElementByTagName('purchase'). That is, like this:

    document.getElementByTagName('customer').item(0).getElementByTagName('purchase') // => [DOMCollection AllPurchasesByTheFirstCustomer]

    [:edit:]Deleted the response, James? Now tell me what it was, I'm curious!
    Last edited by liorean; 01-13-2004 at 01:22 AM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was just wondering whether this is relevant - How can we get childNodes from a custom tag?
    Last edited by brothercake; 01-17-2004 at 02:11 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Last edited by RadarBob; 01-27-2004 at 09:57 PM.

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Not really. getElementsByName exists for a sole reason: To allow gathering of forms, images, links, frames by the name attribute instead of the id attribute. If you have a closer look at the spec you will find that it is a method of [DOM1HTML] and not CORE, anyway, so it's not present in XML documents.

    <http://w3.org/dom/DOMTR>

    What function may be useful is getElementsById, however. But if he wanted to use that one I think he would have tried it instead of getElementsByTagName.



    Brendon, are you aware that ID may not start with a digit?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •