quick question.
I have an array with 3 functions. When I call the specific function I want to perform it does not respond to the specific index within the array. It just performs all functions till it gets to the last function.
Here is the code:
<p id="sometext">Change Color</p>
<script>
function paintRed() {
var text = document.getElementById('sometext');
text.style.color = "red";
}
function paintBlue() {
var text = document.getElementById('sometext');
text.style.color = "blue";
}
function paintYellow() {
var text = document.getElementById('sometext');
text.style.color = "yellow";
}
var arrcolor = [ paintRed(), paintBlue(), paintYellow()];
arrcolor[0]; //This returns the yellow color and not red//
</script>
So my
Change Color
always returns as yellow (The last function in the array) regardless of which index I call i.e (arrcolor[0],arrcolor[1]).Hope it makes sense. Thanks.