best_bMedlem sedan apr. 200425 inlägg Hej
Skulle behöva hjälp med att byta bakgrundsfärg i en enskild cell i
en tabell:
<html>
<head>
<script language="JavaScript">
function blue(){
document.body.bgColor = "blue"
}
</script>
<script language="JavaScript">
function white(){
document.body.bgColor = "white"
}
</script>
</head>
<body bgcolor="gray">
<table width="50%">
<tr>
<td width="50%">
<form>
<input type="button" value="Hej" OnClick="blue()">
</td>
<td width="50%">
<input type="button" value="Då" Onclick="white()">
</td>
</tr>
</table>
</body>
</html>
Alltså det jag vill göra är att när nån clickar på någon av knapparna vill jag göra så den cellen ändrar bakgrundsfärg.
Peter SMedlem sedan dec. 20025 483 inlägg 1: <html>
2: <head>
3: <script language="JavaScript">
4: function blue(obj){
5: while ((obj = obj.parentNode).nodeName != "TD");
6: obj.style.backgroundColor = "blue";
7: }
8: </script>
9:
10: <script language="JavaScript">
11: function white(obj){
12: while ((obj = obj.parentNode).nodeName != "TD");
13: obj.style.backgroundColor = "white";
14: }
15: </script>
16:
17: </head>
18: <body bgcolor="gray">
19: <table width="50%">
20: <tr>
21: <td width="50%">
22: <form>
23: <input type="button" value="Hej" OnClick="blue(this)">
24: </td>
25: <td width="50%">
26: <div><input type="button" value="Då" Onclick="white(this)"></div>
27: </td>
28: </tr>
29: </table>
30: </body>
31: </html>
:)