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. Advertisements

  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. Advertisements

  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. Advertisements

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,227
    Dean H. Saxe
    Jan 3, 2004
  2. Rob Nicholson
    Replies:
    3
    Views:
    1,011
    Rob Nicholson
    May 28, 2005
  3. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    638
    Ranganath
    Oct 21, 2003
  4. Mike
    Replies:
    3
    Views:
    1,227
    Michael Borgwardt
    Jan 9, 2004
  5. A. Brinkmann
    Replies:
    2
    Views:
    1,296
    A. Brinkmann
    Apr 16, 2004
  6. Greg Smith
    Replies:
    35
    Views:
    3,516
    Alex Kay
    Oct 24, 2004
  7. Kwasi
    Replies:
    13
    Views:
    796
    Kwasi Yeboah via JavaKB.com
    Dec 1, 2004
  8. koslows
    Replies:
    0
    Views:
    655
    koslows
    May 12, 2005
Loading...