www.webdeveloper.com
Results 1 to 2 of 2

Thread: Finding the sub-elements of an element

  1. #1
    Join Date
    May 2007
    Location
    Rochester, NY
    Posts
    12

    Finding the sub-elements of an element

    I'm trying to figure out a way to get sub-elements within an element. The basic structure of the page is like this:
    HTML Code:
    <div name="Location">
        <div name="Building"></div>
        <div name="Building"></div>
    <div name="Location">
        <div name="Building"></div>
    <div name="Location">
        <div name="Building"></div>
        <div name="Building"></div>
    Using document.getElementsByName I can find the top level "location" element but when I call getElementsByName on that element it fails saying: "The object doesn't support this method". getElementsByTagName works on the element however the page is huge and I could potentially be looping through hundreds of elements. There could also potentially be 100+ Buildings on a page and looping through each of them to find the ones I want to update just feels ugly.

    Ideally, what I'd like to do is something like document.getElementByName("Location").item(0).getElementByName("Building") but that doesn't appear to work. Does anyone know of a nicer way of doing this?

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    The name attribute is invalid in a div. Use semantic elements in the markup.
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles