View Full Version : I need some elements which control the attributes of other elements
Andrei Todor
08-14-2002, 09:38 AM
I would like to have a dynamic html, in which some elements control the appearance and behaviour of other elements, somethink like:
<html>
<head>
<title> Test </title>
<SCRIPT language=JavaScript>
function changeclick()
{
document.a2.onclick=action();
document.a2.style.color="blue";
}
</SCRIPT>
</head>
<body>
<a name="a1" href="javascript:changeclick()">
Click here
</a>
<br>
<a name="a2" href="#" onclick="null"
style="color:gray">
then here
</a>
</body>
</html>
However, this version doesn't work. Does anyone have an idea to make it work?
glenngv
08-14-2002, 09:57 AM
function changeclick()
{
document.links["a2"].onclick=action; //remove () when assigning onclick to a function
document.links["a2"].style.color="blue";
}
Andrei Todor
08-14-2002, 10:24 AM
Glenn,
I tried your suggestion, but it still doesn't work. Thank you, anyway.
Not exactly sure what you are after but here's something.
Take a look at my website as well, there might be something in my "Scripts" or "CSS" section that will do what you are after;
www.huntingground.freeserve.co.uk
<html>
<head>
<title> Test </title>
<SCRIPT language=JavaScript>
function changeclick(){
document.all["a1"].style.fontSize="16"
document.all["a2"].style.color="blue";
document.all["a2"].style.fontSize="40"
}
function changeclick2(){
document.all["a1"].style.color="red";
document.all["a1"].style.fontSize="40"
document.all["a2"].style.fontSize="16"
}
</SCRIPT>
</head>
<body>
<a id="a1" href="javascript:changeclick()"> Click here </a> <br>
<a id="a2" href="#" onclick="changeclick2()" style="color:gray"> then here </a>
</body>
</html>
Andrei Todor
08-19-2002, 09:15 AM
Thank you, Mr J, but your suggestion still does not work, neither in Netscape4, nor in Netscape6.
Roy Sinclair
08-19-2002, 02:19 PM
Mr J's code was IE specific. Netscape 4 is garbage but the following will work with IE 5+ and Mozilla:
<html>
<head>
<title> Test </title>
<SCRIPT language=JavaScript>
function changeclick(){
var lv = document.getElementById("a1");
lv.style.fontSize="16" ;
lv.style.color="blue";
lv.style.fontSize="40"
}
function changeclick2(){
var lv = document.getElementById("a1");
lv.style.color="red";
lv.style.fontSize="40"
lv.style.fontSize="16"
}
</SCRIPT>
</head>
<body>
<a id="a1" href="#" onclick="changeclick();return false;"> Click here </a> <br>
<a id="a2" href="#" onclick="changeclick2();return false;" style="color:gray"> then here </a>
</body>
</html>
Andrei Todor
08-21-2002, 12:28 PM
Thank you, Roy, for your help.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.