got it
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" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
function Color(id,col){
document.getElementById(id).style.backgroundColor=col;
}
function FontFamily(){
var col=document.getElementById('a1').style.fontFamily;
if (col=="\"verdana\"")
{document.getElementById('a1').style.fontFamily="arial";}
else {document.getElementById('a1').style.fontFamily="verdana";}
}
</script>
</head><body>
<a onclick="Color('d1','red');">Anchor</a><br>
<a onclick="FontFamily();">Font Family</a>
<div id="a1" style='font-family:verdana;'>This is a test of the Emergency Broadcasting System. This is only a test.</div>
<div id="d1" style="width:200px;height:200px;background-color:blue;" ></div>
</body></html>
ok, in this code we have two functions. In the first function, Color, we have two values, id and col that are being retrieved from this line <a onclick="Color('d1','red');">Anchor</a><br> with id being d1 and col being red. When the anchor is clicked the two values are placed into the function and processed.
From what I can tell, in
Code:
document.getElementById(id).style.backgroundColor=col;
document is the entire document that contains the id of "d1", which in this case is
Code:
<div id="d1" style="width:200px;height:200px;background-color:blue;" ></div>
getElementById(id) is the element that is between the div tags. style is
Code:
width:200px;height:200px;background-color:blue;
and style.backgroundColor is blue. the background-color is recognized by removing the dash and changing the letter right after the dash to a capital letter.
The value of various aspects of the element can be altered with commands like
Code:
document.getElementById(id).style.backgroundColor=col
where col is and always will be "red" as is defined by <a onclick="Color('d1','red');">
Once the function runs the values for id and col are lost. I do not want the values to be lost, so in the second function I define the variable with the value of an item that is in the element. In this case I use the value retrieved from the element (a1), which is font-family, which has the value of verdana.
now that "col" has been given the value of "verdana" I say if col="\"verdana\"" change it to arial, else change it to verdana. Now that the value of the item in the element has been changed when I run the function again the value of col will be different.
I do not know why I have to escape the quotes though.
I hope the above makes sense. I may edit this later to make sure the wording is correct.
Bookmarks