The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Change Colour

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #28407

    Is there a way to change the colour of a div as it moves across the screen in the horizontal plane?
    I would need it to change 5 times to different colours and not animate across the spectrum, just suddenly change.

    Any Help Appreciated.


    I don’t quite understand what you’re trying to do, but to change colors with javascript you can do one of several things.

    The first is do something like: document.getElementById(‘yourID’).style = ‘color:#XXXXXX’;

    or, you could use JQuery if you want a little more functionality. I’d recommend using JQuery only if you plan to use it a bunch, otherwise, it’s extra bandwidth for a simple color change.

    Build a function like this:

    function changeColor(color, elementID) {
    document.getElementById(elementID).style = ‘color:’ + color;

    then simply call the function with the color and id on any event you choose.


    the code that Democritus supplied will change the color, as far as when it changes color, you still have to specify that.

    Without knowing more, like how the div moves, and when it should change color, we can’t really offer any more help.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.