J
Jerry Krinock
In the html below, my function changeIt() changes both the text and
the color of an anchor when it is clicked. It works, but it seems
paradoxical and kind of kludgey.
The paradox I see is in the lines marked Note 1 and Note 2. What is
my object1? Is it the anchor, or its font tag? If it's the font tag,
how can it respond to .innerHTML? If it's the anchor, how can it
respond to .color?
The kludge I see is in having to refer to the font by its id. If I
instead pass the 'this' pointer to the function, I can make it change
the text via .innerHTML, but I can't make it change the color.
Obviously the <a> does not have a font, but is there a better way to
do this?
Thanks,
Jerry Krinock
Tested in Safari....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8">
<title>Test</title>
<script type="text/javascript">
function changeIt (anId) {
var object1 = document.getElementById(anId) ;
object1.color = "red" ; //
Note 1
object1.innerHTML = "New Text" ; // Note 2
}
</script>
</head>
<body>
<a href="#" onClick='changeIt("item1")'><font id=item1>Click Me</
font></a><br>
</body>
</html>
the color of an anchor when it is clicked. It works, but it seems
paradoxical and kind of kludgey.
The paradox I see is in the lines marked Note 1 and Note 2. What is
my object1? Is it the anchor, or its font tag? If it's the font tag,
how can it respond to .innerHTML? If it's the anchor, how can it
respond to .color?
The kludge I see is in having to refer to the font by its id. If I
instead pass the 'this' pointer to the function, I can make it change
the text via .innerHTML, but I can't make it change the color.
Obviously the <a> does not have a font, but is there a better way to
do this?
Thanks,
Jerry Krinock
Tested in Safari....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8">
<title>Test</title>
<script type="text/javascript">
function changeIt (anId) {
var object1 = document.getElementById(anId) ;
object1.color = "red" ; //
Note 1
object1.innerHTML = "New Text" ; // Note 2
}
</script>
</head>
<body>
<a href="#" onClick='changeIt("item1")'><font id=item1>Click Me</
font></a><br>
</body>
</html>