...

View Full Version : Class attribute in NS4



meterlink
07-09-2002, 10:59 PM
Hello,
Could you please help me to change dynamically in javascript the class name in <a> tag in NS4 ?
<a id="opsa" class="c" href"...">...</a>

Thank you very much

adios
07-09-2002, 11:41 PM
Gets very messy:


<html>
<head>
<title>untitled</title>
<style type="text/css">

.oldclass1 {
color: #00ff00;
}
.oldclass2 {
background: #00ffff;
}
.newclass1 {
font-style: italic;
color: #ff0000;
}
.newclass2 {
font-weight: bold;
background: #ffff00;
}

</style>
<script type="text/javascript" language="JavaScript">

var NSlinks = new Object();
//linktext: the content of the <a> tag without the class name
//text: the <a>text between</a>
NSlinks['a1'] = {linktext: 'href="javascript&#58;alert(&#92;'test 1&#92;')"' , text: 'test 1 text'};
NSlinks['a2'] = {linktext: 'href="javascript&#58;alert(&#92;'test 2&#92;')"' , text: 'test 2 text'};

function changeCSSclass(id, classname) {
if (!document.layers) document.getElementById(id).className = classname;
else {
var HTML = '<a class="' + classname + '" ' + NSlinks[id].linktext + '>';
HTML += NSlinks[id].text + '</a>';
var l = document['NS' + id];
l.document.write(HTML);
l.document.close();
}
}

</script>
</style>
</head>
<body>
<layer id="NSa1">
<a id="a1" class="oldclass1" href="javascript&#58;alert('test 1')">test 1 text</a>
</layer><br><br>
<layer id="NSa2">
<a id="a2" class="oldclass2" href="javascript&#58;alert('test 2')">test 2 text</a>
</layer><br><br><br>
<a href="#"
onmouseover="changeCSSclass('a1','newclass1')"
onmouseout="changeCSSclass('a1','oldclass1')">change test 1 class</a><br>
<a href="#"
onmouseover="changeCSSclass('a2','newclass2')"
onmouseout="changeCSSclass('a2','oldclass2')">change test 2 class</a>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum