I have the code that will begin with collapsed text, however I do not understand some of the functions. can someone please add comments so I can learn what the scrfipt is doing?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>4. Switch menu</title>
<script language="javascript">
var linx = false;
if(document.all) { linx = true; }
function getObject(id) {
if (linx) {
return document.all[id];
} else {
return document.getElementById(id);
}
}
//This function sets the linked HTML text that will expand paragraph
function toggle(link, divId) {
var linxText = link.innerHTML;
var d = getObject(divId);
if (linxText == 'Create a link') { link.innerHTML = 'A link to close Paragraph'; d.style.display = 'block';
}else {
link.innerHTML = 'Create a link'; d.style.display = 'none';
}
}
</script>
<!-- -->
</head>
<body>
<!-- Paragraph Expand/Collapse Content start -->
4. <a title="show/hide" id="par_link" href="javascript: void(0);" onclick="toggle(this, 'par');" style="text-decoration: none; color:blue; cursor:pointer; ">−</a>
<div id="par" style="padding: 3px;"><p>a. that displays a paragraph of text when clicked. <br />
When the link is clicked again the paragraph should disappear the paragraph should disappear <br />
the paragraph should disappear the paragraph should disappear the paragraph should disappear <br />
the paragraph should disappear the paragraph should disappear the paragraph should disappear<br />
the paragraph should disappear the paragraph should disappear. </p></div>
</div>
<script language="javascript">toggle(getObject('par_link'), 'par');</script>
</body>
</html>
Bookmarks