tiki
04-07-2006, 12:59 PM
Sorry for the dumb question, I'm a Javascript newb.
Basically, I need to add a numeric suffix to the ID so I can apply colors to multiple DOM documents.
The problem is I don't know how to define the numid variable.
Any help would be greatly appreciated.
function update(elemchange)
{
var numid =
switch(elemchange)
{
case "linkcolor": {
var obj = document.getElementById('link' + numid);
obj.style.color="900000";
break;
}
case "textcolor": {
var obj = document.getElementById('text' + numid);
obj.style.color="ff0000";
break;
}
}
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center">
<span id="link1" class="link">link</span>
<span id="link2" class="link">link</span>
<span id="link3" class="link">link</span>
<span id="link4" class="link">link</span>
<span id="link5" class="link">link</span></td>
<td align="center">
<span id="text1" class="text">text</span>
<span id="text2" class="text">text</span>
<span id="text3" class="text">text</span>
<span id="text4" class="text">text</span>
<span id="text5" class="text">text</span></td>
</tr>
<tr>
<td align="center"><a href="#" id="linkcolor" onclick="update('linkcolor')">click</a></td>
<td align="center"><a href="#" id="textcolor" onclick="update('textcolor')">click</a></td> </tr>
</table>
Basically, I need to add a numeric suffix to the ID so I can apply colors to multiple DOM documents.
The problem is I don't know how to define the numid variable.
Any help would be greatly appreciated.
function update(elemchange)
{
var numid =
switch(elemchange)
{
case "linkcolor": {
var obj = document.getElementById('link' + numid);
obj.style.color="900000";
break;
}
case "textcolor": {
var obj = document.getElementById('text' + numid);
obj.style.color="ff0000";
break;
}
}
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center">
<span id="link1" class="link">link</span>
<span id="link2" class="link">link</span>
<span id="link3" class="link">link</span>
<span id="link4" class="link">link</span>
<span id="link5" class="link">link</span></td>
<td align="center">
<span id="text1" class="text">text</span>
<span id="text2" class="text">text</span>
<span id="text3" class="text">text</span>
<span id="text4" class="text">text</span>
<span id="text5" class="text">text</span></td>
</tr>
<tr>
<td align="center"><a href="#" id="linkcolor" onclick="update('linkcolor')">click</a></td>
<td align="center"><a href="#" id="textcolor" onclick="update('textcolor')">click</a></td> </tr>
</table>