getElementsBName and <table>'s

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

    #1

    getElementsBName and <table>'s

    I relatively new to JavaScript and the DOM....

    I have a <table name="xxx"> and I try to a
    document.getEle mentsByName("xx x")

    I don't seem to get the <table> returned in the NodeList returned by
    getElementsByNa me

    If I do a
    nl = document.getEle mentsByTagName( "table")

    I can iterate through the resultant NodeList and find node with
    nl[i].name = "xxx"

    Do <table>'s just not work with getElementsByNa me ?

    Thanks
    Mike


  • Richard Cornford

    #2
    Re: getElementsBNam e and &lt;table&gt ;'s

    "Mike Berger" <mbergerREMOVET HIS@skypoint.co m> wrote in message
    news:vpdankqdi9 l6a5@corp.super news.com...
    <snip>[color=blue]
    >Do <table>'s just not work with getElementsByNa me ?[/color]

    As TABLE elements are not allowed a NAME attribute (according to the
    HTML 4 DTDs) so it is probably unrealistic to expect to be able to
    retrieve them from an HTML DOM by name (with getElementsByNa me). You may
    find some browsers that will let you, in the same way that you will find
    some browsers that will make all attribute values into named properties
    of an element, there will be others that don't. Starting from the basis
    of valid HTML is likely to significantly increase the chances of
    consistent behaviour from DOM methods.

    Richard.


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: getElementsBNam e and &lt;table&gt ;'s

      "Mike Berger" <mbergerREMOVET HIS@skypoint.co m> writes:
      [color=blue]
      > I relatively new to JavaScript and the DOM....
      >
      > I have a <table name="xxx"> and I try to a
      > document.getEle mentsByName("xx x")[/color]

      Table tags don't have a "name" attribute, so your "HTML" is not correct
      HTML.
      [color=blue]
      > I don't seem to get the <table> returned in the NodeList returned by
      > getElementsByNa me[/color]

      Which browser are you using? It seems to be consistent behavior in
      the browsers I have tested, so it's probably not important.

      Are you writing HTML or XHTML? The method getElementsByNa me works
      differently in HTML and XHTML, but the problem seems to be there
      in HTML, which is the more accepting of the two.
      [color=blue]
      > If I do a
      > nl = document.getEle mentsByTagName( "table")
      >
      > I can iterate through the resultant NodeList and find node with
      > nl[i].name = "xxx"
      >
      > Do <table>'s just not work with getElementsByNa me ?[/color]

      I don't *think* so. The getElementsByNa me method finds the DOM
      nodes with a name property that has the right value. Tables don't
      have a DOM property called "name".

      Give the table an id and use getElementById instead.

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • steve stevo

        #4
        Re: getElementsBNam e and &lt;table&gt ;'s

        try using id instead of name

        hope this helps

        Simon Christie

        "Mike Berger" <mbergerREMOVET HIS@skypoint.co m> wrote in message
        news:vpdankqdi9 l6a5@corp.super news.com...[color=blue]
        > I relatively new to JavaScript and the DOM....
        >
        > I have a <table name="xxx"> and I try to a
        > document.getEle mentsByName("xx x")
        >
        > I don't seem to get the <table> returned in the NodeList returned by
        > getElementsByNa me
        >
        > If I do a
        > nl = document.getEle mentsByTagName( "table")
        >
        > I can iterate through the resultant NodeList and find node with
        > nl[i].name = "xxx"
        >
        > Do <table>'s just not work with getElementsByNa me ?
        >
        > Thanks
        > Mike
        >
        >[/color]


        Comment

        • Mike Berger

          #5
          Re: getElementsBNam e and &lt;table&gt ;'s

          Oh... duh........

          Thanks, my bad

          "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
          news:bn6ef6$diq $1$8300dec7@new s.demon.co.uk.. .[color=blue]
          > "Mike Berger" <mbergerREMOVET HIS@skypoint.co m> wrote in message
          > news:vpdankqdi9 l6a5@corp.super news.com...
          > <snip>[color=green]
          > >Do <table>'s just not work with getElementsByNa me ?[/color]
          >
          > As TABLE elements are not allowed a NAME attribute (according to the
          > HTML 4 DTDs) so it is probably unrealistic to expect to be able to
          > retrieve them from an HTML DOM by name (with getElementsByNa me). You may
          > find some browsers that will let you, in the same way that you will find
          > some browsers that will make all attribute values into named properties
          > of an element, there will be others that don't. Starting from the basis
          > of valid HTML is likely to significantly increase the chances of
          > consistent behaviour from DOM methods.
          >
          > Richard.
          >
          >[/color]


          Comment

          Working...