That chameleons change colors to disguise themselves is a common misconception. Scientists believe that the real reason for color changing is to communicate with other chameleons and express their mood, like a reptilian mood ring! If the color happens to match the background, it's completely coincidental.
The also speculate that another changing colors could be advantageous is that it lets them adjust to various temperatures and light situations. For example, if the chameleon is cold, it will change to a darker color to absorb more light!