Lanthan: mit onmouseover/out farbe wechseln

halloele

ich haette da eine kleine frage.

ich habe eben ein div erstellt, welches sich bei onmouseover/out
farblich aendern soll. nun waere es aber noch schoen, wenn sich das div
bei onclick ebenfalls farblich aendert.

wenn ich dies alles so schreib:
       onMouseOver="this.style.backgroundColor = '#1004b2'"
       onMouseOut="this.style.backgroundColor = '#c0bcfa'"
       onclick="this.style.backgroundColor='#1004b2'"
funktioniert es zwar, aber durch das onmouseover/out wechselt
sich dennoch staendig die farbe.

ich habe nun daran gedach eine funktion zu schreiben wie folgt:
       if (onmouseover) this.style.backgroundColor='#1004b2'
       if (onmouseout) this.style.backgroundColor='#c0bcfa'
       if (onclick) this.style.background='#1004b2'

aber so tut es nicht. weiss einer von euch ne moeglichkeit? kann mir
einer n ratschlag geben oder n anstubser?

gruessle Lanthan

  1. Hallo,
    das funktioniert bei mir einwandfrei:
    <body>
    <div id="Layer1" style="position:absolute; width:200px; height:115px; z-index:1"
     onMouseOver="this.style.backgroundColor = '#1004b2'"
           onMouseOut="this.style.backgroundColor = '#c0bcfa'"
           onclick="this.style.backgroundColor='#1004FF'"></div>

    </body>

    Für das onClick die Farbe wechseln, dann siehst du's auch!
    f.

    wenn ich dies alles so schreib:
           onMouseOver="this.style.backgroundColor = '#1004b2'"
           onMouseOut="this.style.backgroundColor = '#c0bcfa'"
           onclick="this.style.backgroundColor='#1004b2'"
    funktioniert es zwar, aber durch das onmouseover/out wechselt
    sich dennoch staendig die farbe.

    1. hi,

      japps weiss, dass es so funktioniert, aber ich moechte das beim
      onclick das div in der farbe bleibt, die im style steht.

      wenn ich danach ueber das naechste div mit der maus geh, soll wieder
      dieser onmouseover/out geschehen und sobald ich auf das neue div
      klick, soll dieses farbig werden, wieder wie im ersten div.

      das erste div soll allerdings daraufhin seine farbe verlieren.

      halt n hover-effekt ohne bild-buttons.

      gruessle lanthan

      Hallo,
      das funktioniert bei mir einwandfrei:
      <body>
      <div id="Layer1" style="position:absolute; width:200px; height:115px; z-index:1"
       onMouseOver="this.style.backgroundColor = '#1004b2'"
             onMouseOut="this.style.backgroundColor = '#c0bcfa'"
             onclick="this.style.backgroundColor='#1004FF'"></div>

      </body>