www.webdeveloper.com
Results 1 to 4 of 4

Thread: ChildNodes set IDs for <tr>

  1. #1
    Join Date
    Jul 2013
    Posts
    31

    ChildNodes set IDs for <tr>

    Hello all,

    I have the following code in which i'm having some problems with:

    Code:
    <div id="ctl00_m_g_022cac31_8157_4fad_acd6_d841986564fc">
      <div class="gray_embossed_tabs">
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
          <tbody>
           <tr>
            <td>
             <ul>
              <li class="selected">
               <a id="alink" href="www.google.com">Google1</a>
              </li>
              <li>
               <a id="alink" href="www.google.com">Google2</a>
              </li>
              <li>
               <a id="alink" href="www.google.com">Google3</a>
              </li>
            </ul>
           </td>
           </tr>
           </tbody>
         </table>
       </div>
    </div>
    On our website this is created by the server in asp and therefore has no ID's on the table or its rows.

    The problem is that we are having a problem with the css of the table without any IDs or Classes I am unable to do this.

    My first thought was to use javascript setAttribute() function, using the only ID there (the first div) to use childNodes[1].childNodes[1] (ext, ext). However, I am unable to get this working as the childNodes don't seem to be set as what i thought.

    At the end of the day I need to be able to modify the css of all the <li> in the above code.

    Can anyone help with my above theory of using setAttribute() or is there possible a better way?

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by B.vidler View Post
    At the end of the day I need to be able to modify the css of all the <li> in the above code.

    Code:
    var listItems = document.getElementById( 
    "ctl00_m_g_022cac31_8157_4fad_acd6_d841986564fc" ).getElementsByTagName( "LI" ) );

  3. #3
    Join Date
    Jul 2013
    Posts
    31
    Omg, after all the things i have tried today, pulling my hair out.

    I had a feeling there was a way to get all the elements nested in another element but always thought you could only do document.getelementbyId.

    Thanks so much!

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    See, for example, the HTML table object in w3schools.com. Its enough to reach the table to get all the rows and cells with the corresponding methods...

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