469,342 Members | 5,847 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

Firefox & getElementById('main_txt') doesn't work

Howdy,

I've got here a sample of my function which is supposed to fade a
certain piece of text to another colour. This line is then located in a
for loop and it works pretty well in IE 6. However, in Firefox, and thus
I assume it will be the same in Netscape and Mozilla, it gives a problem
with the: getElementById('main_txt'). Due to that in setTimeout("",) it
requires the "" signes and thus I can not use the same ones in the
getElement part. IE has no problem with using '' in there, Firefox,
however, does. Can anyone think of how to get around this and make
firefox do this?

window.setTimeout("document.getElementById('main_t xt').style.color =
'rgb("+red+","+green+","+blue+")'",delay*step);

Thanks in advance, Maarten
Jul 23 '05 #1
1 3289
Muffinman wrote:
Howdy,

I've got here a sample of my function which is supposed to fade a
certain piece of text to another colour. This line is then located in a
for loop and it works pretty well in IE 6. However, in Firefox, and thus
I assume it will be the same in Netscape and Mozilla, it gives a problem
with the: getElementById('main_txt'). Due to that in setTimeout("",) it
requires the "" signes and thus I can not use the same ones in the
getElement part. IE has no problem with using '' in there, Firefox,
however, does. Can anyone think of how to get around this and make
firefox do this?

window.setTimeout("document.getElementById('main_t xt').style.color =
'rgb("+red+","+green+","+blue+")'",delay*step);


Let's end this misery:

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html><head>
<title>f-f-f-fader</title>
<meta http-equiv='Content-Type'
content='text/html; charset=ISO-8859-1'>
</head>

<body onload="change_colour('xx','0','0','0');">

<script type="text/javascript">

function change_colour(ele,r,g,b){
var s = document.getElementById(ele);
var dest_red = 202;
var dest_green = 207;
var dest_blue = 222;
var lag = 500;
var steps = 10;

// Ensure values are numbers so can add to them
r = +r; g = +g; b = +b;

var steps_red = (dest_red - r)/steps;
var steps_green = (dest_green - g)/steps;
var steps_blue = (dest_blue - b)/steps;

// Start the timer
s.timer = window.setInterval(function() {
r += steps_red;
g += steps_green;
b += steps_blue;

// If we're at the end (or really close), finish it
if ( r > dest_red || g > dest_green || b > dest_blue) {
s.style.color = 'rgb('
+ dest_red + ','
+ dest_green + ','
+ dest_blue + ')';
s.innerHTML = '<b>I\'m done...</b>';

// Stop the timer
window.clearTimeout(s.timer);
s.timer = null;

} else {

// ensure values are integers
s.style.color = 'rgb('
+ Math.floor(r) + ','
+ Math.floor(g) + ','
+ Math.floor(b) + ')';

// Just to show the values as we go...
s.innerHTML += '<br>' + r + ', ' + g + ', ' + b;
}
}, lag);
}

</script>

<span id="xx" style="color: blue;"><b>HI TO EVERYONE</b></span>

</body>
</html>

--
Zif
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by vadivasbro | last post: by
18 posts views Thread by Gustaf Liljegren | last post: by
7 posts views Thread by 80s.arcade | last post: by
2 posts views Thread by Christina | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.