per JS alle tr rot

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • per JS alle tr rot

    also ich hab folgendes prob:

    klick ich auf ein tr der tabelle soll der hintergrund gelb werden (vorher rot) klick ich auf den nächsten, sollen alle tr's wieder rot werden, der angeklickte gelb.

    wie kann ich dies realisieren. imo hab ich diesen code:

    PHP Code:
    <script type="text/javascript">
    function 
    SetColor(ID){
        var 
    that document.getElementById(ID);
        var 
    acolor that.style.backgroundColor;

        if(
    acolor == ""){
            
    that.style.backgroundColor '#ffffcc';
        }
        else if(
    acolor != ""){
            
    that.style.backgroundColor 'red';
        }
    }
    </
    script
    aber wie finde ich nun raus, wieviele tr's vorhanden sind und wie mache ich ALLE wieder rot ?
    Signatur-Text ...

  • #2
    document.getElementsByTagName( 'tr' ) ??

    Comment


    • #3
      document.getElementsByTagName("tr").style.backgroundColor = '#FFFFFF';

      kommt nur wäre null - aba keine änderung der farbe.
      Last edited by dani_o; 14-11-2007, 12:58.
      Signatur-Text ...

      Comment


      • #4
        document.getElementsByTagName("tr") liefert ein array zurück. und das musst du verarbeiten.

        gruß
        peter
        Nukular, das Wort ist N-u-k-u-l-a-r (Homer Simpson)
        Meine Seite

        Comment


        • #5
          [ Zensiert (Wutausbruch wegen Nichterkennens) ]
          Last edited by dani_o; 14-11-2007, 13:08.
          Signatur-Text ...

          Comment


          • #6
            Für die die s mal brauchen:

            PHP Code:
            <script type="text/javascript">
            function 
            SetColor(ID){
                
                var 
            all document.getElementsByTagName("tr");
                for (var 
            0all.lengthi++) {
                    
            all[i].style.backgroundColor 'red';
                }
                
                var 
            that document.getElementById(ID);
                var 
            acolor that.style.backgroundColor;

                if(
            acolor == ""){
                    
            that.style.backgroundColor '#ffffcc';
                }
                else if(
            acolor != ""){
                    
            that.style.backgroundColor 'red';
                }
            }
            </
            script
            Signatur-Text ...

            Comment

            Working...
            X