Now it's my turn to ask a question... hehe...
This is the most oddicle thing that I've encountered in JavaScript (I think). Instead of the more usual problem of me not being able to figure out HOW to do something, the new kind of question today is, WHY DOESN'T SOMETHING THAT WORKS NOT WORK WHEN IT SHOULD? That probably didn't make sense, so here's what I've got:
function xClr(){
var clrs = new Array("red", "blue", "yellow", "lime", "orange");
var rndClrs = Math.floor(Math.random()*(clrList.length));
var orgClr = clrs[rndClrs];
//var newElem = document.getElementsByTagName("IMG")[3];
//newElem.setAttribute("src", "file:///c:/html/cmm/imgs/alien_planetoids.jpg");
//document.body.appendChild(newElem);
var ap = document.getElementsByTagName("BODY")[0]
//ap.setAttribute("link", "#ff0000");
//alert(ap1.getAttribute("link"));
//ap.setAttribute("alink", "#ff0000");
//alert(ap.getAttribute("alink"));
ap.setAttribute("alink", "#ff0000");
alert(ap.getAttribute("alink"));
}
Basically I'm trying to set the alink, vlink, AND link attributes on the <BODY> tag. First I tested to make sure it works by creating variable, "newElem" and making get the 4th image on the page's ID. Then I set the new SRC using setAttribute('src', 'value'). That worked.
So now I go on and try the body. I set a new variable (ap) to get the BODY tag. That works. Now I set the attribute('link', '#ff0000'). That works fine. I can alert(ap.getAttribute('link')) and I get "#FF0000." Now I go ahead and try ap.setAttribute('alink', 'color'); and it should work. Problem occurs: IT DOES NOT. Question: Why? It does not work with alink or vlink, only with link. Why is that? I tried each one individually with the others commented out, so the problem is not the fact that I am reusing the variable ap (because I'm not). Any suggestions? Thanks....
This is the most oddicle thing that I've encountered in JavaScript (I think). Instead of the more usual problem of me not being able to figure out HOW to do something, the new kind of question today is, WHY DOESN'T SOMETHING THAT WORKS NOT WORK WHEN IT SHOULD? That probably didn't make sense, so here's what I've got:
function xClr(){
var clrs = new Array("red", "blue", "yellow", "lime", "orange");
var rndClrs = Math.floor(Math.random()*(clrList.length));
var orgClr = clrs[rndClrs];
//var newElem = document.getElementsByTagName("IMG")[3];
//newElem.setAttribute("src", "file:///c:/html/cmm/imgs/alien_planetoids.jpg");
//document.body.appendChild(newElem);
var ap = document.getElementsByTagName("BODY")[0]
//ap.setAttribute("link", "#ff0000");
//alert(ap1.getAttribute("link"));
//ap.setAttribute("alink", "#ff0000");
//alert(ap.getAttribute("alink"));
ap.setAttribute("alink", "#ff0000");
alert(ap.getAttribute("alink"));
}
Basically I'm trying to set the alink, vlink, AND link attributes on the <BODY> tag. First I tested to make sure it works by creating variable, "newElem" and making get the 4th image on the page's ID. Then I set the new SRC using setAttribute('src', 'value'). That worked.
So now I go on and try the body. I set a new variable (ap) to get the BODY tag. That works. Now I set the attribute('link', '#ff0000'). That works fine. I can alert(ap.getAttribute('link')) and I get "#FF0000." Now I go ahead and try ap.setAttribute('alink', 'color'); and it should work. Problem occurs: IT DOES NOT. Question: Why? It does not work with alink or vlink, only with link. Why is that? I tried each one individually with the others commented out, so the problem is not the fact that I am reusing the variable ap (because I'm not). Any suggestions? Thanks....