3 lines of code want to display all tags

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Hnatt

    3 lines of code want to display all tags

    for(var i=0;i<document. all.elements.le ngth;i++){
    alert(document. forms[0].elements[i].id);
    }

    This code displays the ids of only controls in a form, but I'd like it to
    display ALL items. For example, not just the ids of buttons, inputs, etc,
    but any <span> elements as well. Is there something I could replace with
    the "elements"? I tried tags but that doesn't work either.

    Thanks!
    Mike


  • Mike Hnatt

    #2
    I figured it out. Here is the code:

    I figured it out. Here is the code:

    for(var i=0;i<document. all.length;i++) {
    alert(document. all[i].id);
    }


    "Mike Hnatt" <dog3@gladsto ne-inc.com> wrote in message
    news:vof9vjcn9a k1be@corp.super news.com...[color=blue]
    > for(var i=0;i<document. all.elements.le ngth;i++){
    > alert(document. forms[0].elements[i].id);
    > }
    >
    > This code displays the ids of only controls in a form, but I'd like it to
    > display ALL items. For example, not just the ids of buttons, inputs, etc,
    > but any <span> elements as well. Is there something I could replace with
    > the "elements"? I tried tags but that doesn't work either.
    >
    > Thanks!
    > Mike
    >
    >[/color]


    Comment

    • Marek A. Stepien

      #3
      Re: I figured it out. Here is the code:

      Mike Hnatt wrote:[color=blue]
      > I figured it out. Here is the code:
      >
      > for(var i=0;i<document. all.length;i++) {
      > alert(document. all[i].id);
      > }[/color]

      This is deprecated and does not work in every browser.
      You should try a better way for this:

      var all=document.ge tElementsByTagN ame("*");

      for(var i=0; i<all.length; i++)
      alert(all[i].id);

      --
      marcoos.org

      Comment

      • Mike Hnatt

        #4
        Re: I figured it out. Here is the code:

        Thanks Marek, I made the changes. I appreciate it,
        Mike

        "Marek A. Stepien" <mam.dosc@spa.m u> wrote in message
        news:bm8dmb$rut $1@nemesis.news .tpi.pl...[color=blue]
        > Mike Hnatt wrote:[color=green]
        > > I figured it out. Here is the code:
        > >
        > > for(var i=0;i<document. all.length;i++) {
        > > alert(document. all[i].id);
        > > }[/color]
        >
        > This is deprecated and does not work in every browser.
        > You should try a better way for this:
        >
        > var all=document.ge tElementsByTagN ame("*");
        >
        > for(var i=0; i<all.length; i++)
        > alert(all[i].id);
        >
        > --
        > marcoos.org
        >[/color]


        Comment

        Working...