QuHno
Außer Betrieb
Ein wenig umgekehrte Logik hilft:
Funktioniert hier wie gewünscht. Manche Browser setzen für die JS Eigenschaften keine default Werte ein und das verwirrt arme Scripte(r wie mich) schon einmal
HTML:
<!doctype html>
<html>
<head>
<title>toggletest</title>
<script>
function nix(){};
function toggleDiv(str){
var elem = document.getElementById(str);
/*
Egal welchen Wert es hat, selbst wenn es undefiniert ist, so lange es nicht 'none' ist, mache es zu 'none',
wenn es 'none' ist, mache es zu 'block'
*/
elem.style.display = (elem.style.display != 'none') ? 'none' : 'block';
}
</script>
</head>
<body>
<p>
<a href="javascript:nix();" onclick="toggleDiv('SubCat1');">hide</a>
</p>
<div id="SubCat1">
Test Test Test Test
</div>
</body>
</html>
HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>toggletest</title>
<script type="text/javascript">
function nix(){};
function toggleDiv(o_Link, theId){
var elem = document.getElementById(theId);
if(elem){
elem.style.display = (elem.style.display != 'none')?'none':'block';
if( typeof( o_Link.innerHTML ) != 'undefined' ) {
o_Link.innerHTML = (o_Link.innerHTML != 'show') ? 'show':'hide';
}
}
return;
}
</script>
</head>
<body>
<p>
<a href="javascript:nix();" onclick="toggleDiv(this,'SubCat1');">toggle</a>
</p>
<div id="SubCat1">
SubCat1
</div>
<p>
<a href="javascript:nix();" onclick="toggleDiv(this,'SubCat2');">toggle</a>
</p>
<div id="SubCat2">
SubCat2
</div>
</body>
</html>
Zuletzt bearbeitet: