Nested tags & getElementsByTagName

Discussion in 'Javascript' started by souporpower@gmail.com, Dec 3, 2008.

  1. Guest

    Hi

    I have in HTML nested tags like

    <span id=1 class=myclass1> <span id=2 class=myclass2>....</span></
    span>

    In Javascript I do

    nodeList=document.getElementsByTagName('span');

    The nodeList does not contain the span with id=2 for some strange
    reason.

    Can someone please tell me how to obtain *all* of the tags in the
    document regardless
    of nesting?

    Thanks
     
    , Dec 3, 2008
    #1
    1. Advertising

  2. SAM Guest

    Le 12/3/08 10:00 PM, a écrit :
    > Hi
    >
    > I have in HTML nested tags like
    >
    > <span id=1 class=myclass1> <span id=2 class=myclass2>....</span></
    > span>
    >
    > In Javascript I do
    >
    > nodeList=document.getElementsByTagName('span');



    nodelist = document.getElementsByTagName('SPAN');

    >
    > The nodeList does not contain the span with id=2 for some strange
    > reason.


    ???

    id="2"
    class="myclass2"

    with quotes or double quotes

    and then even ... an ID can't begin with a number !

    > Can someone please tell me how to obtain *all* of the tags in the
    > document regardless of nesting?


    And why that for ?


    Déjà qu'on se demande pourquoi il faut une class différente pour chaque
    sous-span ? !

    Why do you need special sub-classes for sub-spans ?

    span.myClass { color: red }
    span.myClass span { color: blue
    span.myClass span span { color: green }

    <span class="myclass"> red
    <span> blue
    <span> green
    </span>
    </span>
    </span>



    --
    sm
     
    SAM, Dec 3, 2008
    #2
    1. Advertising

  3. David Mark Guest

    On Dec 3, 4:00 pm, "" <>
    wrote:
    > Hi
    >
    > I have in HTML nested tags like
    >
    > <span id=1 class=myclass1> <span id=2 class=myclass2>....</span></
    > span>
    >
    > In Javascript I do
    >
    > nodeList=document.getElementsByTagName('span');
    >
    > The nodeList does not contain the span with id=2 for some strange
    > reason.


    For one, don't start ID's with number. ID's such as "1", "2", etc.
    are clearly a bad idea.

    [snip]
     
    David Mark, Dec 3, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dean H. Saxe
    Replies:
    0
    Views:
    1,040
    Dean H. Saxe
    Jan 3, 2004
  2. =?Utf-8?B?Sm9l?=

    SelectNodes vs. GetElementsByTagName

    =?Utf-8?B?Sm9l?=, Nov 2, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    41,195
    =?Utf-8?B?Sm9l?=
    Nov 2, 2005
  3. mynamehere
    Replies:
    0
    Views:
    460
    mynamehere
    Dec 14, 2003
  4. Danny
    Replies:
    1
    Views:
    430
    wooks
    Jul 23, 2004
  5. Ragnar Heil
    Replies:
    5
    Views:
    7,558
    Ragnar Heil
    Apr 27, 2005
Loading...

Share This Page