By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,659 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,659 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.