Prototype - toggleClassName() 方法
此方法切换元素的 CSS className 并返回元素。
语法
element.toggleClassName( className );
返回值
返回 HTML 元素。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
if( !$('mutsu').hasClassName('fruit') ) {
// This will return false
alert( "Class name is not set" );
}
$('mutsu').toggleClassName('fruit');
// This will toggle the class presence
if( $('mutsu').hasClassName('fruit') ) {
// This returns true
alert( "Now Class name is set" );
}
}
</script>
</head>
<body>
<p>单击按钮查看结果。</p>
<div id = "mutsu" class = "apple">
<p>This is test division.</p>
</div>
<br />
<input type = "button" value = "showResult" onclick = "showResult();"/>
</body>
</html>

prototype_element_object.html